;(function () {
  new Vue({
    el: '#contract-creat2',
    data: {
      contractId:hlUrlUtil.GetQueryString('id'),
      getCtPrevData: JSON.parse(window.sessionStorage.getItem('EDIT_CONTRACT_FIRST_STEP')),
      contractDetail:{},
      setYear: {
        list: [{name:'季度',code:3},{name:'半年',code:6},{name:'1年',code:1},{name:'2年',code:2},{name:'3年',code:3},{name:'4年',code:4},{name:'5年',code:5}],
        active: null
      },
      setRent: {
        list: [{name:'按固定租金', type: 'M'}, {name: '按实际天数', type: 'D'}],
        active: 'M'
      },
      setUnit: {
        one: {
          list: ['元/平米/天', '元/平米/月']
        },
        two: {
          list: ['元/个/天', '元/个/月']
        },
        nIndex: 0,
        active: 'one'
      },
      acreage: 0, //到时候删除，临时计算用
      unitTotalAcreage:0,  // 所选单元总面积
      oPrice: null,
      dRent: null,
      mRent: null,
      menoy: null,
      //租金押金计费
      rentBill: {
        oPrice: null,    // 租金单价
        dRent: null,     // 日租金
        mRent: null,    //  月租金
        bet: null,      // 押几月
        pay: null,      // 付几月
        menoy: null,    // 押多少元
        proportion: null, // 滞纳金比例
        rentPercent:null,
        day: null
      },
      dayRentPriceAlert:'',
      monthRentPriceAlert:'',
      //阶梯租金
      rentLadder: [],
			copyRentLadderArr: [],
      //免租期
      freePeriod: [],
      //费项
      costItem: [],
      sDate: null,
      bDate: null,
      eDate: null,
      //付款计划数据
      rentFlag: true,
      cTIndex: null,  // 选中的费项索引
      cTData: [],    // 费项数据
      cTType: null,   // 费项类型
      mzqFlag:true,
      jtzjFlag:true,
      billDate: {
        list: [
          {name: '账单开始前', code: 'B'},
          {name: '账单开始后', code: 'A'}
        ],
        act: 'B',
        list1: [
          {name: '固定天数', code: 'TS'},
          {name: '固定日期', code: 'RQ'}
        ],
        act1: 'TS',
        dates: [],
        dateIndex: null,
        dateName: null,
        putIndex: null,
        dateFlag: false,
        sqDate: null,
      },
      payplanData: {contract: {}, expenses: []},
      oPrice: null,
      dRent: null,
      mRent: null,
      menoy: null,
			copyRentLadderArr: [],
      reletFlag: hlUrlUtil.GetQueryString('relet'),
			quanxian: JSON.parse(localStorage.getItem('permissions')),

			//**********************营业额抽成 data  start **************************
			turnoverArr: [],
			turnoverCode: 'FD',
			tableArr: [
				{base_val_down_limit:'0', base_val_up_limit: '', commission_percent:'', commission_down_limit: '', commission_up_limit: '', late_fee_percent: '', payemnt_period: ''},
			],
			turnoverCheckBox: 'N',
      yyeFlag: false,
      paymentType:[{
        name:'同租赁周期',
        code:'BL',
       },{
         name:'自选日期',
         code:'CM',
       }],
       paymentTypeCode:'BL',
       billDateQH:[{
         name:'账单开始前',
         code:'B',
       },{
         name:'账单开始后',
         code:'A'
       }],
       billDateQHcode:'B',
       billDay:[{name:'固定天数',code:'TS'},{name:'固定日期',code:'RQ'}],
       billDaycode:'TS',
       dayNum:'',
       paymentCycle:'',//付款周期
			// **************************** 营业额抽成 data end **************************

			// 合同模块 2019-05-17 迭代 start
			ladderRentArr: [],
			ladderRentActive: 'N',
      // 合同模块 2019-05-17 迭代 end

      // 改版20190705
      rentDepositFlag:true,
      rentProperty:'',
      TemTypeList: ['Word', 'PDF'],
      selectedTemTypeList: [],
      temList: [],
      selectedTemList: '',
      TemplateModulShow: false,

      isYJflag:false, //是否展示押金模块
      isGDflag:false,  //是否展示租金模块
    },
    filters: {
      toFixed2: function (n) {
        return Number(n).toFixed(2)
      },
      formatNum:function(item){
        if(!item)return
        return hlNumberUtil.formatNum(item)
      },
      time (time) {
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      }
    },
    watch:{
      paymentCycle(){
        this.tableArr.map(item =>{
          item.payemnt_period = this.paymentCycle
        })
      },
      payDate(){
        if(this.turnoverCheckBox == 'Y'){
          this.paymentCycle = this.rentBill.pay
        }
      }
    },
    computed: {
      payDate:function(){
        return this.rentBill.pay
      },
      ptotal: function () {
        var result = 0;
        this.costItem.map(function(item) {
          if (item.expense_type == 'P') {
            result++
          }
        })
        return result
      },
      ototal: function () {
        var result = 0;
        this.costItem.map(function(item) {
          if (item.expense_type == 'O') {
            result++
          }
        })
        return result
      },
      ttotal: function () {
        var result = 0;
        this.costItem.map(function(item) {
          if (item.expense_type == 'T') {
            result++
          }
        })
        return result
      },
      // 工位数量
      wpNum: function () {
        var num = 0;
        if (this.getCtPrevData.projectInfo.wpdata) {
          var d = this.getCtPrevData.projectInfo.wpdata;
          var arr = []
          for (var i = 0; i < d.length; i++) {
            for (var j = 0; j < d[i].stop.length; j++) {
              arr.push(d[i].stop[j])
            }
          }
          for (var k = 0; k < arr.length; k++) {
            num++
          }
        }
        return num;
      },
      // 车位数量
      stNum: function () {
        var num = 0;
        if (this.getCtPrevData.projectInfo.stdata) {
          var d = this.getCtPrevData.projectInfo.stdata;
          var arr = []
          for (var i = 0; i < d.length; i++) {
            for (var j = 0; j < d[i].stop.length; j++) {
              arr.push(d[i].stop[j])
            }
          }
          for (var k = 0; k < arr.length; k++) {
            num++
          }
        }
        return num;
      },
      // 单元总面积
      utAge: function () {
        var num = 0;
        if (this.getCtPrevData.projectInfo.units) {
          var d = this.getCtPrevData.projectInfo.units;
          for (var i = 0; i < d.length; i++) {
            num += Number(d[i].unit_acreage)
          }
        }
        return num;
      },
    },
    methods: {
      // 改版20190705开始
        //选择文档类型
        selectedTemType(item) {
          let index = this.selectedTemTypeList.indexOf(item)
          if (index > -1) {
            this.selectedTemTypeList.splice(index, 1)
          } else {
            this.selectedTemTypeList.push(item)
          }
        },
        //选择文档
        selectedTem(item) {
          this.selectedTemList = item.id
        },
       //新增合同模板
       addNewTem() {
        hlUrlUtil.goTo('billTemplate', {
          ddtab: true
        }, true)
      },
       //合同预览/打印
       previewTemPrint() {
        this.TemplateModulShow = true
        var that = this
        hlhttp.get({
          url: 'contract/print_templates',
          success: function(data) {
            that.temList = data
          }
        })
      },
      //导出合同模板
      exportTemplate() {
        if (!this.selectedTemTypeList.length) {
          hl.toast('请选择文件类型')
          return
        }
        if (!this.selectedTemList) {
          hl.toast('请选择模板')
          return
        }
        this.saveSubmit(4)
      },
      // 检测固定租金是否填写完整
      checkFixedRent(){
        if (!(this.oPrice && this.dRent && this.mRent)) {
          hl.toast('请完善固定租金信息')
          return false
        }
        return true
      },
      //展示租金押金
      showRentDeposit(){
        this.rentDepositFlag = !this.rentDepositFlag
        this.rentBill.bet = null
        this.menoy = ''
        this.rentBill.proportion = null
      },
       // 获取选中租金计算周期
      getSelfRent(){
        var that = this
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CIWU',
            config_name: 'CW_RENT_CALCULATE_PERIOD_TYPE_CONFIG',
          },
          success: function (res) {
            that.rentProperty = [res[0].dictProperty]
          }
        })
      },
      //预览合同模板
      preview(id) {
        this.saveSubmit(3,id)
      },
      previewImage: function(url) {
        var imageExt = ['jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'PNG'];
        var pdfExt = ['pdf', 'PDF'];
        var officeExt = ['docx','doc','xlsx','xls','xlt'];
        var imageFlag = false;
        var pdfFlag = false;
        var officeFlag = false;

        imageExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) imageFlag = true;
        })

        if (imageFlag) {
          $.imageShow([url])
          return
        }
        pdfExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) pdfFlag = true;
        })
        if (pdfFlag) {
          $.previewPDF(url)
          return
        }

        officeExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) officeFlag = true
        })
        if (officeFlag) {
          $.previewOffice(url)
          return
        }
        hl.toast('暂不支持该格式')
      },
      downloadFiles(fileUrls) {
        fileUrls.forEach(v => {
          this.createIFrame(v);
        })
      },
      createIFrame(url) {
        setTimeout(() => {
          let frame = document.createElement('iframe');
          frame.style = 'display: none;';
          frame.class = 'multi-download';
          frame.src = url,

            document.body.appendChild(frame);
          setTimeout(function() {
            document.body.removeChild(frame);
          }, 1000);

        })
      },
      // 改版20190705结束
      hidePlanBox(){
        $('#pay-plan, .ct-ceat-btn').hide()
      },
			// *************** 合同模块 2019-05-17 迭代 start ***************
			//设置阶梯方式
			ladderRentSelect (item) {
				// if (this.setRent.active == 'M') {
				// 	hl.toast('按固定租金计算月租金时不可选择当日递增')
				// 	return
				// };
				this.ladderRentActive = item.dictCode
				$('#pay-plan, .ct-ceat-btn').hide()
      },

			//阶梯方式
			ladderRentConfig () {
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'CIWU', config_name: 'CW_DIFFERENTIAL_PRICING_EFFECTIVE_TYPE'},
					success: (data) => {
						this.ladderRentArr = data;
					}
				})
			},
			// *************** 合同模块 2019-05-17 迭代 end ***************
			//************************************* 营业额抽成开始 ***************************************
      // 选择收款日（周期）
      selectPayment(code){
        this.paymentTypeCode = code
      },
      //抽成类型
			CHOUCHENGDt () {
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'HETN', config_name: 'HT_COMMISSION_TYPE'},
					success: (data) => {
						this.turnoverArr = data;
					}
				})
			},
			//隐藏营业额表格
			hideYYE () {
				this.yyeFlag = false;
				this.turnoverCheckBox = 'N';
        this.turnoverCode = 'FD';
        this.paymentTypeCode = 'BL';
        this.billDateQHcode = 'B';
        this.billDaycode = 'TS';
        this.dayNum = '';
        this.paymentCycle = '';
				this.tableArr = [
					{base_val_down_limit:'0', base_val_up_limit: '', commission_percent:'', commission_down_limit: '', commission_up_limit: '', late_fee_percent: '', payemnt_period: ''},
			  ]
				$('#pay-plan, .ct-ceat-btn').hide()
			},
			//显示营业额表格
			showYYE () {
				this.yyeFlag = true;
				$('#pay-plan, .ct-ceat-btn').hide()
			},
			// 新增基数列表
			addYYE (i) {
				if (this.tableArr.length > 1) {
					if (!this.tableArr[this.tableArr.length-2].base_val_up_limit) {
						hl.toast('请填写上一个基数上限')
						return
					}
				}
				this.tableArr.push({base_val_down_limit: this.tableArr[this.tableArr.length-1].base_val_up_limit ? this.tableArr[this.tableArr.length-1].base_val_up_limit : this.tableArr[this.tableArr.length-1].base_val_down_limit, base_val_up_limit: '', commission_percent:'', commission_down_limit: '', commission_up_limit: '', late_fee_percent: '', payemnt_period: ''})
				if (this.tableArr[0].payemnt_period) {
					this.tableArr.map(item => {
						item.payemnt_period = this.tableArr[0].payemnt_period
					})
				}
				$('#pay-plan, .ct-ceat-btn').hide()
			},
			//删除某个基数
			removeYYE (i) {
				this.tableArr.splice(i, 1)
				this.tableArr[0].base_val_down_limit = '0';
				if (this.tableArr.length > 1) {
					for (let i = 0; i < this.tableArr.length; i++) {
						if (i+1 < this.tableArr.length) {
							this.tableArr[i+1].base_val_down_limit = ''
							this.tableArr[i+1].base_val_down_limit = this.tableArr[i].base_val_up_limit
						}
					}
				}
				$('#pay-plan, .ct-ceat-btn').hide()
			},
			//修改基数上限
			blurYYE (i) {
				$('#pay-plan, .ct-ceat-btn').hide()
				if (Number(this.tableArr[i].base_val_down_limit) >= Number(this.tableArr[i].base_val_up_limit)) {
					hl.toast('基数上限必须大于基数下限')
					this.tableArr[i].base_val_up_limit = '';
					return
				}
				if (this.tableArr.length-1 >= i+1) {
					this.tableArr[i+1].base_val_down_limit = this.tableArr[i].base_val_up_limit
				}
				this.tableArr[this.tableArr.length-1].base_val_down_limit = this.tableArr[this.tableArr.length-2].base_val_up_limit
			},
			//与租金取其高
			takeHigh () {
        $('#pay-plan, .ct-ceat-btn').hide()
				if (!(this.oPrice && this.dRent && this.mRent && this.rentBill.bet && this.rentBill.menoy && this.rentBill.pay)) {
					hl.toast('请完善租金押金信息')
					this.turnoverCheckBox = 'N';
					return
				}
				this.turnoverCheckBox = this.turnoverCheckBox == 'N' ? 'Y' : 'N';
				if (this.turnoverCheckBox == 'Y') {
          this.paymentCycle = this.rentBill.pay
					this.tableArr.map(item => {
						item.payemnt_period = this.rentBill.pay
					})

				}
			},
			//抽成下限判断
			isLowerYYE (i) {
        $('#pay-plan, .ct-ceat-btn').hide()
        if (!this.tableArr[i].commission_up_limit) return;
				if (Number(this.tableArr[i].commission_up_limit) < Number(this.tableArr[i].commission_down_limit)) {
					this.tableArr[i].commission_down_limit = '';
					hl.toast('抽成上限不得大于抽成下限')
					return
				}
			},
			//抽成上限判断
			isUpYYE (i) {
        $('#pay-plan, .ct-ceat-btn').hide()
        if (!this.tableArr[i].commission_up_limit) return;
				if (Number(this.tableArr[i].commission_up_limit) < Number(this.tableArr[i].commission_down_limit)) {
					this.tableArr[i].commission_up_limit = '';
					hl.toast('抽成上限不得小于抽成下限')
					return
				}
			},
			//合同类型
			selectType (item) {
				$('#pay-plan, .ct-ceat-btn').hide()
				this.turnoverCode = item.dictCode
			},
			//营业额付款周期
			yyePayment () {
				$('#pay-plan, .ct-ceat-btn').hide()
				this.tableArr.map(item => {
					if (this.tableArr[0].payemnt_period) {
            item.payemnt_period = this.tableArr[0].payemnt_period
            if (item.payemnt_period < 1) {
							item.payemnt_period = 1
						}
					}
				})
			},
			//抽成比例
			yyeProportion () {
				$('#pay-plan, .ct-ceat-btn').hide()
			},
			//********************************* 营业额抽成结束 **************************************
      //收款日
      dateSet: function (code) {
        this.billDate.act = code;
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      blurHide: function () {
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      completion: function () {
        if (this.billDate.dates.length > 0) {
          if (!$('.dateJs').eq(this.billDate.dates.length-1).val()) {
            return
          }
        }
        var ld = {
          begin_date: $('.dateKs').eq(this.billDate.dates.length-1).val(),
          end_date: $('.dateJs').eq(this.billDate.dates.length-1).val()
        };
        var cp = {
          begin_date: beginDate.value,
          end_date: endDate.value
        }

        var self = this;
        hlhttp.get({
          url: 'fill_up_custom_period',
          data: {
            last_period: JSON.stringify(ld),
            contract_period: JSON.stringify(cp)
          },
          success: function (res) {
            res.customPeriod.map(function (item, index) {
              self.billDate.dates.push({begin_date: hlDateUtil.formatUTCDate(item.beginDate, 'yyyy-MM-dd'), end_date: hlDateUtil.formatUTCDate(item.endDate, 'yyyy-MM-dd')})
            })

            self.billDate.dates.map(function (item, index) {
              setTimeout(function() {
                $('.dateKs').eq(index).attr('value', item.begin_date)
                $('.dateJs').eq(index).attr('value', item.end_date)
              }, 300);
            })
          }
        })

      },

      dateSet1: function (code) {
        this.billDate.act1 = code;
        if (this.billDate.act1 == 'RQ') {
          if (this.rentBill.day > 31) {
            this.rentBill.day = 31
          }
          if (this.rentBill.day < 1) {
            this.rentBill.day = 1
          }
        }
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      blurDate: function () {
        this.$nextTick(function () {
          if (this.billDate.act1 == 'RQ') {
            if (this.rentBill.day > 31) {
              this.rentBill.day = 31
            }

            if (this.rentBill.day < 1) {
              this.rentBill.day = 1
            }
          }
        })
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      addDate: function (i) {
        if (this.billDate.dates.length > 0) {
          if (!this.billDate.dates[this.billDate.dates.length-1].end_date) {
            return
          }
        }
        this.billDate.dates.push({begin_date: null, end_date: null})
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      yzDate: function () {
        var self = this;
        function toDou(n) {
          return n<10 ? '0' +n : '' +n;
        }

        $(document).on('click', '.day-item', function(event) {
          if (self.billDate.dateName == 'dateKs') {
              $('#pay-plan, .ct-ceat-btn').hide()
            if (self.billDate.dates.length >= 1) {
              var flag = false;
              for (var i = 0; i < self.billDate.dates.length; i++) {
                if (self.billDate.dateIndex > 0) {
                  if (hlDateUtil.shellDate(self.billDate.dates[self.billDate.dateIndex-1].end_date) >= hlDateUtil.shellDate($('.setYear .select-name').text()+'-'+toDou($('.setMonth .select-name').text())+'-'+toDou($(this).text()))) {
                    flag = true;
                  }
                }
              }
              if (hlDateUtil.shellDate(self.billDate.dates[self.billDate.dateIndex].end_date) < hlDateUtil.shellDate($('.setYear .select-name').text()+'-'+toDou($('.setMonth .select-name').text())+'-'+toDou($(this).text()))) {
                flag = true;
              }
              if (flag) {
                hl.toast('开始时间不能大于结束时间或不能小于上一个结束时间')
                setTimeout(function() {
                  $('.dateKs').eq(self.billDate.dateIndex).attr('value', '')
                  self.billDate.dates[self.billDate.dateIndex].begin_date = null
                  self.billDate.dateName = '';
                }, 200);
                return
              }
              if (endDate.value == '') {
                hl.toast('租赁期限不能为空')
                setTimeout(function() {
                  $('.dateKs').eq(self.billDate.dateIndex).attr('value', '')
                  self.billDate.dates[self.billDate.dateIndex].begin_date = null
                  self.billDate.dateName = '';
                }, 200);
                return
              }
              if (hlDateUtil.shellDate(beginDate.value) > hlDateUtil.shellDate($('.setYear .select-name').text()+'-'+toDou($('.setMonth .select-name').text())+'-'+toDou($(this).text()))) {
                hl.toast('开始时间不能小于租赁期限')
                setTimeout(function() {
                  $('.dateKs').eq(self.billDate.dateIndex).attr('value', '')
                  self.billDate.dates[self.billDate.dateIndex].begin_date = null
                  self.billDate.dateName = '';
                }, 200);
                return
              }
              if (hlDateUtil.shellDate(endDate.value) < hlDateUtil.shellDate($('.setYear .select-name').text()+'-'+toDou($('.setMonth .select-name').text())+'-'+toDou($(this).text()))) {
                hl.toast('开始时间不能大于租赁期限')
                setTimeout(function() {
                  $('.dateKs').eq(self.billDate.dateIndex).attr('value', '')
                  self.billDate.dates[self.billDate.dateIndex].begin_date = null
                  self.billDate.dateName = '';
                }, 200);
                return
              }
            }
            self.billDate.dates[self.billDate.dateIndex].begin_date = $('.setYear .select-name').text()+'-'+toDou(Number($('.setMonth .select-name').text()))+'-'+toDou($(this).text())
            self.billDate.dateName = '';
          }

          if (self.billDate.dateName == 'dateJs') {
              $('#pay-plan, .ct-ceat-btn').hide()
            if (!self.billDate.dates[self.billDate.dateIndex].begin_date) {
              hl.toast('起始不能为空')
              setTimeout(function() {
                $('.dateJs').eq(self.billDate.dateIndex).attr('value', '')
                self.billDate.dates[self.billDate.dateIndex].end_date = null
                self.billDate.dateName = '';
              }, 200);
              return
            }
            if (hlDateUtil.shellDate(self.billDate.dates[self.billDate.dateIndex].begin_date) > hlDateUtil.shellDate($('.setYear .select-name').text()+'-'+toDou(Number($('.setMonth .select-name').text()))+'-'+toDou($(this).text()))) {
              hl.toast('不能小于开始时间')
              setTimeout(function() {
                $('.dateJs').eq(self.billDate.dateIndex).attr('value', '')
                self.billDate.dates[self.billDate.dateIndex].end_date = null
                self.billDate.dateName = '';
              }, 200);
              return
            }
            self.billDate.dates[self.billDate.dateIndex].end_date = $('.setYear .select-name').text()+'-'+toDou(Number($('.setMonth .select-name').text()))+'-'+toDou($(this).text())
            self.billDate.dateName = '';
          }
        });
      },
      queryDate: function () {
        $('#pay-plan, .ct-ceat-btn').hide()
        var timeOB = JSON.parse(JSON.stringify(this.billDate.dates));
        var self = this;
        if (!timeOB.length) {
          self.billDate.dateFlag = false;
          self.costItem[self.billDate.putIndex].customPeriod = []
          return
        }
        var flag = false;
        timeOB.map(function(item) {
          if (!item.begin_date) {
            flag = true;
          }
          if (!item.end_date) {
            flag = true;
          }
        })
        if (flag) {
          hl.toast('开始时间或结束时间不能为空')
          timeOB = []
          return
        }

        hlhttp.put({
          url: 'check_custom_period_policy',
          data: {
            custom_period: JSON.stringify(this.billDate.dates)
          },
          success: function (res) {
            if (res.result == 'Y') {
              self.billDate.dateFlag = false;
              self.costItem[self.billDate.putIndex].customPeriod = JSON.parse(JSON.stringify(timeOB));
            }
            if (res.result == 'N') {
              hl.toast('日期不能有交集')
            }
          }
        })
      },
      delDate: function (i) {
        this.billDate.dates.splice(i, 1)
        for (var i = 0; i < this.billDate.dates.length; i++) {
          $('.dateKs').eq(i).attr('value', this.billDate.dates[i].begin_date)
          $('.dateJs').eq(i).attr('value', this.billDate.dates[i].end_date)
        }
      },
      inpIndex: function (i, n) {
        this.billDate.dateIndex = i;
        this.billDate.dateName = n;
      },
      putEindex: function (i) {
        this.billDate.dateFlag = true;
        this.billDate.putIndex = i;
        this.billDate.dates = JSON.parse(JSON.stringify(this.costItem[i].customPeriod));

        var self = this;
        setTimeout(function() {
          for (var j = 0; j < self.billDate.dates.length; j++) {
            $('.dateKs').eq(j).attr('value', self.billDate.dates[j].begin_date)
            $('.dateJs').eq(j).attr('value', self.billDate.dates[j].end_date)
          }
        }, 200);
      },
      resetDate: function () {
        this.billDate.dates = [];
      },
      calDate: function () {
        this.billDate.dates = [];
        this.billDate.dateFlag = false;
      },

      // 获取合同详情
      getContractDetail:function(){
        var self = this;
        let url = 'contract'
        let data = {id:self.contractId}
        if (hlUrlUtil.GetQueryString('relet') == 'true') {
          url = 'contract/renewal'
          data = {contract_id: self.contractId}
        }
        hlhttp.get({
          url: url,
          data: data,
          success: function (data) {
            self.contractDetail = data
            var prevData = self.getCtPrevData;
            // 如果第一步时编辑更改了合同类型 或者 面积、工位数 ，则租金押金信息及阶梯租金信息全重置为空
            // console.log(prevData.contactType.active + '~' +  data.contractType)
            // console.log(self.utAge + '~' + data.rentAcreage)
            // console.log(self.wpNum + '~' + data.rentWpCount);
            ///续租
            if (self.reletFlag) {
              self.rentBill = {
                'oPrice': Number(data.rentPrice).toFixed(2),
                'dRent': Number(data.rentPriceDay).toFixed(2),
                'mRent': Number(data.rentPriceMonth).toFixed(2),
                'proportion':data.rentLateFeePercent,
                'menoy': Number(data.deposit).toFixed(2),
                'bet':data.depositPeriod,
                'pay':data.paymentPeriod,
                'day': '',
                'act': data.billDateBOA,
                'act1': data.billDateFixType
              }

              self.oPrice = Number(data.rentPrice).toFixed(2);
              self.dRent = Number(data.rentPriceDay).toFixed(2);
              self.mRent = Number(data.rentPriceMonth).toFixed(2);
              self.setRent.active = data.rentWay;
              if(data.rentPriceUnit === 'D')self.setUnit.nIndex = 0;
              if(data.rentPriceUnit === 'M')self.setUnit.nIndex = 1;
            }
						//营业额
						if (data.commissionPaymentPeriod) {
              self.turnoverCode = data.commissionTypeCode
              self.paymentTypeCode = data.paymentDateConfig
              self.billDateQHcode = data.billDateBOA
              self.billDaycode  = data.billDateFixType
              self.dayNum = data.commissionDateFixNum
							if (data.commissionRules.length) {
                self.paymentCycle = data.commissionPaymentPeriod
                self.turnoverCheckBox = data.compareRentAmtFlag
                self.paymentTypeCode = data.paymentDateConfig
                self.billDateQHcode = data.commissionDateBoa
                self.billDaycode = data.commissionDateFixType
                self.dayNum = data.commissionDateFixNum
								self.tableArr = []
								data.commissionRules.map((item, index) => {
									self.tableArr.push(
										{
											base_val_down_limit: item.baseValDownLimit,
											base_val_up_limit: index == data.commissionRules.length-1 ? '' : item.baseValUpLimit,
											commission_percent: item.commissonPercent,
											commission_down_limit: item.commissionDownLimit,
											commission_up_limit: item.commissionUpLimit,
											late_fee_percent: item.lateFeePercent,
										}
									)
								})
							}
							self.turnoverCheckBox = data.compareRentAmtFlag
							self.yyeFlag = true
						}

            //合同编辑
            if (!self.reletFlag) {
              if(prevData.contactType.active === data.contractType && Number(self.utAge).toFixed(2) == Number(data.rentAcreage).toFixed(2) && self.wpNum == data.rentWpCount){
                // 租金押金
                self.rentBill = {
                  'oPrice': Number(data.rentPrice).toFixed(2),
                  'dRent': Number(data.rentPriceDay).toFixed(2),
                  'mRent': Number(data.rentPriceMonth).toFixed(2),
                  'proportion':data.rentLateFeePercent,
                  'menoy': Number(data.deposit).toFixed(2),
                  'bet':data.depositPeriod,
                  'pay':data.paymentPeriod,
                  'day': data.billDateFixNum,
                  'act': data.billDateBOA,
                  'act1': data.billDateFixType
                }

                self.oPrice = Number(data.rentPrice).toFixed(2);
                self.dRent = Number(data.rentPriceDay).toFixed(2);
                self.mRent = Number(data.rentPriceMonth).toFixed(2);
                self.menoy = Number(data.deposit).toFixed(2)

                self.setRent.active = data.rentWay;
                if(data.rentPriceUnit === 'D')self.setUnit.nIndex = 0;
                if(data.rentPriceUnit === 'M')self.setUnit.nIndex = 1;
                // 阶梯租金
                if(data.rentIncreseDate.split(',').length > 1){
                  var rentArr = [];
                  var rentIndex = 1;
                  data.rentIncreseDate.split(',').map(function(_item){
                    if(rentIndex < data.rentIncreseDate.split(',').length){
                      rentArr.push({
                        'time':data.rentIncreseDate.split(',')[rentIndex],
                        'lv':data.rentIncresePercent.split(',')[rentIndex] * 100 + '%',
                        'dj':data.rentIncresePrice.split(',')[rentIndex],
                        'rz':data.rentIncreseDay.split(',')[rentIndex],
                        'yz':data.rentIncreseMonth.split(',')[rentIndex]
                      })
                      rentIndex++;
                    }
                  })
                  self.rentLadder = rentArr;
									self.copyRentLadderArr = JSON.parse(JSON.stringify(rentArr));
                }
              }

              SqDate.setAttribute('value', hlDateUtil.formatUTCDate(new Date().getTime(), 'yyyy-MM-dd'));
              if (data.firstPaymentDate) {
                SqDate.setAttribute('value', hlDateUtil.formatUTCDate(data.firstPaymentDate, 'yyyy-MM-dd'));
              }
              // 免租期
              if(data.freeDate){
                data.freeDate.split(',').map(function(_item){
                  self.freePeriod.push({'btime':_item.split('~')[0],'etime':_item.split('~')[1]})
                })
              }
              // 费项
              if(data.expenses){
                data.expenses.map(function(_item){
                  var arr = []
                  _item.customPeriod.map(function (val) {
                    arr.push({begin_date: hlDateUtil.formatUTCDate(val.beginDate, 'yyyy-MM-dd'), end_date: hlDateUtil.formatUTCDate(val.endDate, 'yyyy-MM-dd')})
                  })
                  self.costItem.push({
                    'expense_name':_item.expenseName,
                    'price':_item.price || _item.price == 0 ? _item.price.toString() : '',
                    'amount':_item.amount || _item.amount == 0 ? _item.amount.toString() : '',
                    'priceDay':_item.priceDay || _item.priceDay == 0  ? _item.priceDay.toString(): '',
                    'priceMonth':_item.priceMonth || _item.priceMonth == 0  ? _item.priceMonth.toString(): '',
                    'priceDayCopy':_item.priceDay || _item.priceDay == 0  ? _item.priceDay.toString(): '',
                    'priceMonthCopy':_item.priceMonth || _item.priceMonth == 0  ? _item.priceMonth.toString(): '',
                    'expense_period':_item.expensePeriod,
                    'late_fee':Number(_item.lateFee * 100).toFixed(2) + '%',
                    expense_type:_item.expenseType,
                    'customPeriod': arr,
										unitsVal: _item.unitsVal ? _item.unitsVal : '',
										unitsCode: _item.unitsCode ? _item.unitsCode : '',
                  })
                })
              }
            }
            console.log(self.costItem)
            self.getCostItem();
          }
        })
      },

      showContractDetail:function(data){
        var self = this;
        if(hlNumberUtil.isEmptyObject(this.contractDetail)){
          setTimeout(function(){self.showContractDetail(this.contractDetail)},1000)
        }
        // 日期
        if (!data.signTime) {
          $('#signedDate').attr('value',hlDateUtil.formatUTCDate(new Date().getTime(),'yyyy-MM-dd'))
        }
        if (!data.firstPaymentDate) {
          $('#SqDate').attr('value',hlDateUtil.formatUTCDate(new Date().getTime(),'yyyy-MM-dd'))
        }
        $('#signedDate').attr('value',hlDateUtil.formatUTCDate(data.signTime,'yyyy-MM-dd'))
        $('#beginDate').attr('value',hlDateUtil.formatUTCDate(data.beginDate,'yyyy-MM-dd'))
        $('#endDate').attr('value',hlDateUtil.formatUTCDate(data.endDate,'yyyy-MM-dd'))
        // 阶梯租金
        if(this.rentLadder.length !== 0){
          var zdate = $('.zdate');
          for (var i = 0; i < this.rentLadder.length; i++) {
            zdate.eq(i).attr('value', this.rentLadder[i].time)
          }
        }
        // 免租期
        if(this.freePeriod.length !== 0){
          var bkdate = $('.bkdate');
          var ekdate = $('.ekdate');
          for (var j = 0; j < this.freePeriod.length; j++) {
            bkdate.eq(j).attr('value', this.freePeriod[j].btime)
            ekdate.eq(j).attr('value', this.freePeriod[j].etime)
          }
        }

      },
      //隐藏付款计划
      hideFkjH: function (val,e,type,i, dm) {
        if(val === 'qdrq'){
          $('#pay-plan, .ct-ceat-btn').hide()
          return false;
        }
        $('#pay-plan, .ct-ceat-btn').hide()


        if (!type) {
          this.rentBill.menoy = JSON.parse(JSON.stringify(this.menoy))
          if (!this.menoy) {
            this.rentBill.menoy = Number(this.rentBill.bet*this.rentBill.mRent).toFixed(4)
            this.menoy = Number(this.rentBill.bet*this.rentBill.mRent).toFixed(2)
          }
        }
        // 押金月份
        if (type == 'bet') {
          if (this.rentBill.mRent != 0) {
            if (this.rentBill.mRent < 0) {
              this.rentBill.mRent = null;
              hl.toast('数字必须大于0')
							this.turnoverCheckBox = 'N'
              return
            }
            if (this.rentBill.bet != 0) {
              if (!Number(this.rentBill.bet)) {
                this.rentBill.bet = null;
								this.turnoverCheckBox = 'N'
                hl.toast('填写数字')
                return
              }
            }
          }

          this.rentBill.menoy = Number(this.rentBill.bet*this.rentBill.mRent).toFixed(4)
          this.menoy = Number(this.rentBill.bet*this.rentBill.mRent).toFixed(2)
        }
        // 租金付出月份
        if (type == 'pay') {
          if (this.rentBill.pay < 0) {
            this.rentBill.pay = '';
            hl.toast('数字必须大于0')
						this.turnoverCheckBox = 'N'
            return
          }
          if (this.rentBill.pay == 0) {
            this.rentBill.pay = ''
            hl.toast('不能为0月')
						this.turnoverCheckBox = 'N'
            return
          }
          if (!Number(this.rentBill.pay)) {
            this.rentBill.pay = '';
            hl.toast('填写数字')
						this.turnoverCheckBox = 'N'
            return
          }
					if (this.yyeFlag) {
						this.tableArr[0].payemnt_period = this.rentBill.pay
					}
        }
        // 周期性费项
        if (type == 'po') {
          if (!this.costItem[i].expense_name) {
            hl.toast('请先选择费项名')
            this.costItem[i].price = '';
            this.costItem[i].amount = ''
            this.costItem[i].priceDay = ''
            this.costItem[i].priceMonth = ''
            this.costItem[i].expense_period = ''
            this.costItem[i].unitsVal = ''
            this.costItem[i].unitsCode = ''
            return
          }

					if (dm == 'd') {
						this.costItem[i].priceDayCopy = JSON.parse(JSON.stringify(this.costItem[i].priceDay))
					}
					if (dm == 'm') {
						this.costItem[i].priceMonthCopy = JSON.parse(JSON.stringify(this.costItem[i].priceMonth))
					}
					if (this.costItem[i].priceDay && !this.costItem[i].priceMonth) {
					  this.costItem[i].priceMonth = Number(this.costItem[i].priceDay*this.rentProperty/12).toFixed(2);
					  this.costItem[i].priceMonthCopy = Number(this.costItem[i].priceDay*this.rentProperty/12).toFixed(4);
					}
					if (!this.costItem[i].priceDay && this.costItem[i].priceMonth) {
					  this.costItem[i].priceDay = Number(this.costItem[i].priceMonth*12/this.rentProperty).toFixed(2);
					  this.costItem[i].priceDayCopy = Number(this.costItem[i].priceMonth*12/this.rentProperty).toFixed(4);
          }

          if (this.costItem[i].price < 0) {
            this.costItem[i].price = null;
          }
          if (this.costItem[i].amount < 0) {
            this.costItem[i].amount = null;
          }
          if (this.costItem[i].priceDay < 0) {
            this.costItem[i].priceDay = null;
            this.costItem[i].priceDayCopy = null;
          }
          if (this.costItem[i].priceMonth < 0) {
            this.costItem[i].priceMonth = null;
            this.costItem[i].priceMonthCopy = null;
          }
          if (this.costItem[i].expense_period < 0) {
            this.costItem[i].expense_period = null;
          }
        }
      },
      //租金下拉选择
      setUnitGr: function (n) {
        this.setUnit.nIndex = n;
        this.rentBill.oPrice = '';
        this.rentBill.dRent = '';
        this.rentBill.mRent = '';
        this.rentBill.bet = '';
        this.rentBill.menoy = '';
        this.rentBill.pay = '';
        this.rentLadder = [];
        this.copyRentLadderArr = [];
        this.freePeriod = [];
        this.dayRentPriceAlert = '';
        this.monthRentPriceAlert = '';
				this.oPrice = '';
				this.dRent = '';
				this.mRent = '';
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      //补零
      toZero: function (n) {
        return n < 10 ? '0' + n : '' + n;
      },
       //设置年份
       setYearLink: function (n,type) {
        $('#pay-plan, .ct-ceat-btn').hide()
        this.setYear.active = type;
        var end = ''
        if (!beginDate.value) {
          var d = new Date();
          var begin = d.getFullYear()+"-"+this.toZero(d.getMonth()+1)+"-"+this.toZero(d.getDate());
          if(type == '季度' || type == '半年'){
            end = hlDateUtil.monthInterval(d,n)
          }else{
            end = (d.getFullYear()+n)+"-"+this.toZero(d.getMonth()+1)+"-"+this.toZero(d.getDate()-1);
          }
          beginDate.setAttribute('value', begin);
          endDate.setAttribute('value', end);
        } else {
          if(type == '季度' || type == '半年'){
            end = hlDateUtil.monthInterval(beginDate.value,n)
          }else{
            end = hlDateUtil.dateInterval(beginDate.value, n)
          }
        }
        beginDate.setAttribute('value', beginDate.value);
        endDate.setAttribute('value', end);
      },
      //选择月租金日付月付
      setRentMD: function (type) {
        $('#pay-plan, .ct-ceat-btn').hide()
        this.setRent.active = type;

				if (type == 'M') {
					this.ladderRentActive = 'N'
				}
      },
      //计算租金押金中的租金单价、日租金、月租金    三者任意一项改动同时更新另外两项金额
      calculateRent: function (n, i,e) {
        var self = this
        $('#pay-plan, .ct-ceat-btn').hide()
        if(!this.validateNumber(n,e))return false;

        if (this.wpNum) {
          this.acreage = this.wpNum
        } else {
          this.acreage = this.utAge
        }
        if (n === null) return;

        if (n != null) {
          if (n != 0) {
            if (n < 0) {
              hl.toast('数字必须大于0')
              this.dRent = null;
              this.mRent = null;
              this.oPrice = null;
              return
            }
            if (!Number(n)) {
              hl.toast('请填写数字')
              this.dRent = null;
              this.mRent = null;
              this.oPrice = null;
              return
            }
          }
        }
        // i == 1 为租金单价  i == 2 为日租金  i == 3 为月租金
        // 如果租金单价、日租金、月租金有值的情况下则不做联动计算
        if (this.oPrice && this.dRent && this.mRent){
          self.isSatisfyMinPrice()
          if (this.setUnit.nIndex === 1) {
            if (i == 1) {
              this.rentBill.oPrice = Number(JSON.parse(JSON.stringify(this.oPrice))).toFixed(4)
            }
            if (i == 2) {
              this.rentBill.dRent = Number(JSON.parse(JSON.stringify(this.dRent))).toFixed(4)
            }
            if (i == 3) {
              this.rentBill.mRent = Number(JSON.parse(JSON.stringify(this.mRent))).toFixed(4)
            }
          }

          if (this.setUnit.nIndex !== 1) {
            if (i == 1) {
              this.rentBill.oPrice = Number(JSON.parse(JSON.stringify(this.oPrice))).toFixed(4)
            }
            if (i == 2) {
              this.rentBill.dRent = Number(JSON.parse(JSON.stringify(this.dRent))).toFixed(4)
            }
            if (i == 3) {
              this.rentBill.mRent = Number(JSON.parse(JSON.stringify(this.mRent))).toFixed(4)
            }
          }

          return false;
        }

        // 当租金单价 、 日租金 、 月租金没有值时，输入租金单价做联动处理
        //  租金单价为按天计算
        if(this.setUnit.nIndex === 0){
          if (i == 1) {
            this.rentBill.oPrice = Number(n).toFixed(4)
            this.oPrice = Number(n).toFixed(2)
            if(!this.rentBill.dRent && this.rentBill.dRent !== 0) {
              this.rentBill.dRent = Number(this.rentBill.oPrice*this.acreage).toFixed(4);
              this.dRent = Number(JSON.parse(JSON.stringify(this.rentBill.dRent))).toFixed(2);
            }
            if(!this.rentBill.mRent && this.rentBill.mRent !== 0){
              this.rentBill.mRent = Number(this.rentBill.oPrice*this.acreage*this.rentProperty/12).toFixed(4);
              this.mRent = Number(JSON.parse(JSON.stringify(this.rentBill.mRent))).toFixed(2);
            }
          }
          if (i == 2) {
            this.rentBill.dRent = Number(n).toFixed(2)
            this.dRent = Number(n).toFixed(2)
            if(!this.rentBill.oPrice && this.rentBill.oPrice !== 0) {
              this.rentBill.oPrice = Number(this.rentBill.dRent/this.acreage).toFixed(4);
              this.oPrice = Number(JSON.parse(JSON.stringify(this.rentBill.oPrice))).toFixed(2);
            }
            if(!this.rentBill.mRent && this.rentBill.mRent !== 0) {
              this.rentBill.mRent = Number(this.rentBill.dRent*this.rentProperty/12).toFixed(4);
              this.mRent = Number(JSON.parse(this.rentBill.mRent)).toFixed(2);
            }
          }
          if (i == 3) {
            this.rentBill.mRent = Number(n).toFixed(2)
            this.mRent = Number(n).toFixed(2)
            if(!this.rentBill.oPrice && this.rentBill.oPrice !== 0) {
              this.rentBill.oPrice = Number(this.rentBill.mRent*12/this.rentProperty/this.acreage).toFixed(4);
              this.oPrice = Number(JSON.parse(JSON.stringify(this.rentBill.oPrice))).toFixed(2);
            }
            if(!this.rentBill.dRent && this.rentBill.dRent !== 0) {
              this.rentBill.dRent = Number(this.rentBill.mRent*12/this.rentProperty).toFixed(4);
              this.dRent = Number(JSON.parse(JSON.stringify(this.rentBill.dRent))).toFixed(2);
            }
          }
        }
        //  租金单价为按月计算
        if (this.setUnit.nIndex !== 0) {
          if (i == 1) {
            this.rentBill.oPrice = Number(n).toFixed(2)
            this.oPrice = Number(n).toFixed(2)
            if(!this.rentBill.dRent && this.rentBill.dRent !== 0) {
              this.rentBill.dRent = Number(this.rentBill.oPrice*this.acreage*12/this.rentProperty).toFixed(4);
              this.dRent = Number(JSON.parse(JSON.stringify(this.rentBill.dRent))).toFixed(2);
            }
            if(!this.rentBill.mRent && this.rentBill.mRent !== 0) {
              this.rentBill.mRent = Number(this.rentBill.oPrice*this.acreage).toFixed(4);
              this.mRent = Number(JSON.parse(JSON.stringify(this.rentBill.mRent))).toFixed(2);
            }
          }
          if (i == 2) {
            this.rentBill.dRent = Number(n).toFixed(2)
            this.dRent = Number(n).toFixed(2)
            if(!this.rentBill.oPrice && this.rentBill.oPrice !== 0) {
              this.rentBill.oPrice = Number(this.rentBill.dRent*this.rentProperty/12/this.acreage).toFixed(4);
              this.oPrice = Number(JSON.parse(JSON.stringify(this.rentBill.oPrice))).toFixed(2);
            }
            if(!this.rentBill.mRent && this.rentBill.mRent !== 0) {
              this.rentBill.mRent = Number(this.rentBill.dRent*this.rentProperty/12).toFixed(2);
              this.mRent = Number(JSON.parse(JSON.stringify(this.rentBill.mRent))).toFixed(2);
            }
          }
          if (i == 3) {
            this.rentBill.mRent = Number(n).toFixed(2)
            this.mRent = Number(n).toFixed(2)
            if(!this.rentBill.oPrice && this.rentBill.oPrice !== 0) {
              this.rentBill.oPrice = Number(this.rentBill.mRent/this.acreage).toFixed(2);
              this.oPrice = Number(JSON.parse(JSON.stringify(this.rentBill.oPrice))).toFixed(2);
            }
            if(!this.rentBill.dRent && this.rentBill.dRent !== 0) {
              this.rentBill.dRent = Number(this.rentBill.mRent*12/this.rentProperty).toFixed(2);
              this.dRent = Number(JSON.parse(JSON.stringify(this.rentBill.dRent))).toFixed(2);
            }
          }
        }

        this.isSatisfyMinPrice()
      },
      //删除租金押金
      delRent: function () {
        $('#pay-plan, .ct-ceat-btn').hide()
        this.rentBill = { oPrice: null, dRent: null, mRent: null, bet: null, pay: null, proportion: null, day: this.rentBill.day };
        this.setRent.active = 'M';
        this.rentLadder = [];
        this.freePeriod = [];
        this.rentFlag = false;
        this.mzqFlag = false;
        this.jtzjFlag = false;
        this.dayRentPriceAlert = '';
        this.monthRentPriceAlert = '';

				this.oPrice = '';
				this.dRent = '';
				this.mRent = '';
				this.menoy = '';
				this.turnoverCheckBox = 'N'
      },
      addRent:function(){
        this.rentFlag = true;
        this.mzqFlag = true;
        this.jtzjFlag = true;
      },
      //新增阶梯租金
      addRentLd: function () {
        if (!beginDate.value) {
          hl.toast('请填写租赁开始时间')
          return
        }
        if (!endDate.value) {
          hl.toast('请填写租赁结束时间')
          return
        }
        if (!this.rentBill.oPrice && this.rentBill.oPrice !== 0) {
          hl.toast('租金押金不能为空')
          return
        }
        if (!this.rentBill.dRent && this.rentBill.dRent !== 0) {
          hl.toast('日租金不能为空')
          return
        }
        if (!this.rentBill.mRent && this.rentBill.mRent !== 0) {
          hl.toast('月租金不能为空')
          return
        }
				let flag = false;
				this.rentLadder.map(item => {
					if (!item.lv || !item.dj || !item.dj || !item.rz || !item.yz) {
						flag = true;
					}
				})
				if (flag) {
					hl.toast('请完善上一个阶梯租金信息')
					return
				}
        $('#pay-plan, .ct-ceat-btn').hide()
        this.rentLadder.push({time: '', lv: '', dj: '', rz: '', yz: ''})
				this.copyRentLadderArr.push({time: '', lv: '', dj: '', rz: '', yz: ''})
      },
      //去除百分比
      cancelbfb: function (data,i,str,n) {
        data[i][str] = n.replace('%', '')
      },
      //添加百分比
      addbfb: function (n, i) {
        if (n) {
          this.costItem[i].late_fee = n + '%'
        } else {
          this.costItem[i].late_fee = '0%'
        }
      },
      //删除数据
      delLd: function (i, data) {
        $('#pay-plan, .ct-ceat-btn').hide()
        data.splice(i, 1)
				this.copyRentLadderArr.splice(i, 1)
      },



      //计算阶梯租金
      // s == 1 为递增率  s == 2 为租金单价  s == 3 为日租金  s == 4 为月租金
      calculateRentLd: function (n, i, s,e) {
        $('#pay-plan, .ct-ceat-btn').hide()
        if(!this.validateNumber(n,e)){
          return false;
        }
        if (n != '0') {
          if (!Number(n)) {
            hl.toast('请填写数字')
            return
          }
        }
        if (this.wpNum) {
          this.acreage = this.wpNum
        } else {
          this.acreage = this.utAge
        }

        if (this.rentLadder[i].dj && this.rentLadder[i].lv && this.rentLadder[i].rz && this.rentLadder[i].yz) {
					if (s == 1) {
						this.copyRentLadderArr[i].lv = JSON.parse(JSON.stringify(this.rentLadder[i].lv))
					}
					if (s == 2) {
						this.copyRentLadderArr[i].dj = JSON.parse(JSON.stringify(this.rentLadder[i].dj))
					}
					if (s == 3) {
						this.copyRentLadderArr[i].rz = JSON.parse(JSON.stringify(this.rentLadder[i].rz))
					}
					if (s == 4) {
						this.copyRentLadderArr[i].yz = JSON.parse(JSON.stringify(this.rentLadder[i].yz))
					}
					return
				};
        // 递增率更改
        if (s == 1) {
          // nIndex === 0 所取租金单价单位为按天计算
          // nIndex !== 0 所取租金单价单位为按月计算
          if (this.rentLadder.length > 1) {
            this.rentLadder[i].dj = (Number(this.rentLadder[i-1].dj*(n/100))
                                  + Number(this.rentLadder[i-1].dj)).toFixed(2);
						//副本
						this.copyRentLadderArr[i].dj = (Number(this.rentLadder[i-1].dj*(n/100))
						                      + Number(this.rentLadder[i-1].dj)).toFixed(4);
          } else {
            this.rentLadder[i].dj = (Number(this.rentBill.oPrice*(n/100))
                                  + Number(this.rentBill.oPrice)).toFixed(2);
						//副本
						this.copyRentLadderArr[i].dj = (Number(this.rentBill.oPrice*(n/100))
						                      + Number(this.rentBill.oPrice)).toFixed(4);
          }
          if (this.setUnit.nIndex === 0) {
            this.rentLadder[i].rz = Number(this.rentLadder[i].dj*this.acreage).toFixed(2);
            this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(2);
						//副本
						this.copyRentLadderArr[i].rz = Number(this.rentLadder[i].dj*this.acreage).toFixed(4);
						this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(4);
          } else {
            this.rentLadder[i].rz = Number(this.rentLadder[i].dj*this.acreage*12/this.rentProperty).toFixed(2);
            this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(2);
						//副本
						this.copyRentLadderArr[i].rz = Number(this.rentLadder[i].dj*this.acreage*12/this.rentProperty).toFixed(4);
						this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(4);
          }
          this.rentLadder[i].lv = n + '%';
					//副本
					this.copyRentLadderArr[i].lv = n;
        }
        // 租金单价更改
        if (s == 2) {
          // nIndex === 0 所取租金单价单位为按天计算
          // nIndex !== 0 所取租金单价单位为按月计算
          if (this.setUnit.nIndex === 0) {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].lv = Number(n/this.rentLadder[i-1].dj*100-100).toFixed(2) + '%';
              this.rentLadder[i].rz = Number(n*this.acreage).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(2);
							//副本
							this.copyRentLadderArr[i].lv = Number(n/this.rentLadder[i-1].dj*100-100).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n*this.acreage).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(4);
            } else {
              this.rentLadder[i].lv = Number(n/this.rentBill.oPrice*100-100).toFixed(2) + '%';
              this.rentLadder[i].rz = Number(n*this.acreage).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(2);
							//副本
							this.copyRentLadderArr[i].lv = Number(n/this.rentBill.oPrice*100-100).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n*this.acreage).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(4);
            }
          } else {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].lv = Number(n/this.rentLadder[i-1].dj*100-100).toFixed(2) + '%';
              this.rentLadder[i].rz = Number(n*this.acreage*12/this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(2);
							//副本
							this.copyRentLadderArr[i].lv = Number(n/this.rentLadder[i-1].dj*100-100).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n*this.acreage*12/this.rentProperty).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(4);
            } else {
              this.rentLadder[i].lv = Number(n/this.rentBill.oPrice*100-100).toFixed(2) + '%';
              this.rentLadder[i].rz = Number(n*this.acreage*12/this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(2);
							//副本
							this.copyRentLadderArr[i].lv = Number(n/this.rentBill.oPrice*100-100).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n*this.acreage*12/this.rentProperty).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(4);
            }
          }
        }
        // 日租金更改
        if (s == 3) {
          if (this.setUnit.nIndex === 0) {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n/this.acreage).toFixed(2);
              this.rentLadder[i].rz = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n/this.rentLadder[i-1].rz*100-100).toFixed(2) + '%';
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(2);
							//副本
							this.copyRentLadderArr[i].dj = Number(n/this.acreage).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n).toFixed(4);
							this.copyRentLadderArr[i].lv = Number(n/this.rentLadder[i-1].rz*100-100).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n/this.acreage).toFixed(2);
              this.rentLadder[i].rz = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n/this.rentBill.dRent*100-100).toFixed(2) + '%';
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(2);
							//副本
							this.copyRentLadderArr[i].dj = Number(n/this.acreage).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n).toFixed(4);
							this.copyRentLadderArr[i].lv = Number(n/this.rentBill.dRent*100-100).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage*this.rentProperty/12).toFixed(4);
            }
          } else {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n/this.acreage*this.rentProperty/12).toFixed(2);
              this.rentLadder[i].rz = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n/this.rentLadder[i-1].rz*100-100).toFixed(2) + '%';
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(2);
							//副本
							this.copyRentLadderArr[i].dj = Number(n/this.acreage*this.rentProperty/12).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n).toFixed(4);
							this.copyRentLadderArr[i].lv = Number(n/this.rentLadder[i-1].rz*100-100).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n/this.acreage*this.rentProperty/12).toFixed(2);
              this.rentLadder[i].rz = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n/this.rentBill.dRent*100-100).toFixed(2) + '%';
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(2);
							//副本
							this.copyRentLadderArr[i].dj = Number(n/this.acreage*this.rentProperty/12).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n).toFixed(4);
							this.copyRentLadderArr[i].lv = Number(n/this.rentBill.dRent*100-100).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj*this.acreage).toFixed(4);
            }
          }
        }
        // 月租金更改
        if (s == 4) {
          if (this.setUnit.nIndex === 0) {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n*12/this.rentProperty/this.acreage).toFixed(2);
              this.rentLadder[i].lv = Number(n/this.rentLadder[i-1].yz*100-100).toFixed(2) + '%';
              this.rentLadder[i].rz = Number(n*12/this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(n).toFixed(2);
							//副本
							this.copyRentLadderArr[i].dj = Number(n*12/this.rentProperty/this.acreage).toFixed(4);
							this.copyRentLadderArr[i].lv = Number(n/this.rentLadder[i-1].yz*100-100).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n*12/this.rentProperty).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(n).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n*12/this.rentProperty/this.acreage).toFixed(2);
              this.rentLadder[i].lv = Number(n/this.rentBill.mRent*100-100).toFixed(2) + '%';
              this.rentLadder[i].rz = Number(n*12/this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(n).toFixed(2);
							//副本
							this.copyRentLadderArr[i].dj = Number(n*12/this.rentProperty/this.acreage).toFixed(4);
							this.copyRentLadderArr[i].lv = Number(n/this.rentBill.mRent*100-100).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n*12/this.rentProperty).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(n).toFixed(4);
            }
          } else {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n/this.acreage).toFixed(2);
              this.rentLadder[i].lv = Number(n/this.rentLadder[i-1].yz*100-100).toFixed(2) + '%';
              this.rentLadder[i].rz = Number(n*12/this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(n).toFixed(2);
							//副本
							this.copyRentLadderArr[i].dj = Number(n/this.acreage).toFixed(4);
							this.copyRentLadderArr[i].lv = Number(n/this.rentLadder[i-1].yz*100-100).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n*12/this.rentProperty).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(n).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n/this.acreage).toFixed(2);
              this.rentLadder[i].lv = Number(n/this.rentBill.mRent*100-100).toFixed(2) + '%';
              this.rentLadder[i].rz = Number(n*12/this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(n).toFixed(2);
							//副本
							this.copyRentLadderArr[i].dj = Number(n/this.acreage).toFixed(4);
							this.copyRentLadderArr[i].lv = Number(n/this.rentBill.mRent*100-100).toFixed(4);
							this.copyRentLadderArr[i].rz = Number(n*12/this.rentProperty).toFixed(4);
							this.copyRentLadderArr[i].yz = Number(n).toFixed(4);
            }
          }
        }
      },
      //新增免租时间
      addFreePd: function () {
        $('#pay-plan, .ct-ceat-btn').hide()
        // if (!this.rentBill.oPrice || !this.rentBill.dRent || !this.rentBill.mRent) {
        //   hl.toast('租金押金不能为空')
        //   return
        // }
        this.freePeriod.push({btime: '', etime: ''})
      },
      //新增费项
      addCostItem: function (type) {
        $('#pay-plan, .ct-ceat-btn').hide()
        if (type == 'P') {
          this.costItem.push({unitsVal: '', unitsCode: '', expense_name: '', amount: '', price: '', priceDay: '', priceMonth: '', priceDayCopy: '', priceMonthCopy: '', expense_period: '', expense_type: 'P', late_fee: '', customPeriod: []})
        }
        if (type == 'O') {
          this.costItem.push({unitsVal: '', unitsCode: '', expense_name: '', amount: '', price: '', priceDay: '', priceMonth: '', priceDayCopy: '', priceMonthCopy: '', expense_period: '', expense_type: 'O', late_fee: ''})
        }
        if (type == 'T') {
          this.costItem.push({unitsVal: '', unitsCode: '', expense_name: '', amount: '', price: '', priceDay: '', priceMonth: '', priceDayCopy: '', priceMonthCopy: '', expense_period: '', expense_type: 'T', late_fee: ''})
        }
      },
      //隐藏费项选择框
      hideExpenseSelect:function(){
        // $('.abs-costitem').hide()
      },
      //返回上一步
      prevData: function () {
        this.freePeriod = [];
        this.sDate = signedDate.value;
        this.bDate = beginDate.value;
        this.eDate = endDate.value;
        this.unitTotalAcreage = this.utAge;
        this.getCtPrevData = JSON.parse(window.sessionStorage.getItem('CREATED_CONTRACT_FIRST_STEP'));
        var zdate = document.querySelectorAll('.zdate');
        for (var i = 0; i < this.rentLadder.length; i++) {
          this.rentLadder[i].time = zdate[i].getAttribute('value')
					this.copyRentLadderArr[i].time = zdate[i].getAttribute('value')
          if (!this.rentLadder[i].time) {
            this.rentLadder.splice(i, 1)
						this.copyRentLadderArr.splice(i, 1)
          }
        }
        for (var c = 0; c < this.costItem.length; c++) {
          if (!this.costItem[c].expense_name) {
            this.costItem.splice(c, 1)
          }
        }
        var bkdate = document.querySelectorAll('.bkdate');
        var ekdate = document.querySelectorAll('.ekdate');
        for (var j = 0; j < bkdate.length; j++) {
          this.freePeriod.push({btime: bkdate[j].getAttribute('value'), etime: ekdate[j].getAttribute('value')})
          if (!this.freePeriod[i].btime || !this.freePeriod[i].etime) {
            this.freePeriod.splice(i, 1)
          }
        }
        this.billDate.sqDate = SqDate.value;
        window.sessionStorage.setItem('EDIT_CONTRACT_SECOND_STEP', JSON.stringify(this.$data))
        if (hlUrlUtil.GetQueryString('relet') == 'true') {
          hlUrlUtil.goTo('contractEdit1',{id: hlUrlUtil.GetQueryString('id'), relet: true, ddtab:true})
          return
        }
        hlUrlUtil.goTo('contractEdit1',{id: hlUrlUtil.GetQueryString('id'), ddtab:true})
      },

      //验证工位单元
      yzunitwp: function () {
        if (this.getCtPrevData.projectInfo.units.length > 0) {
          this.setUnit.active ='one'
        } else {
          this.setUnit.active ='two'
        }
      },
      //获取费项
      getCostItem: function () {
        var _this = this;
        // _this.costItem = []
        hlhttp.get({
          url: 'project/config_expenditures',
          data: {project_id: _this.getCtPrevData.projectInfo.project_id},
          success: function (res) {

            res.some(item =>{
              if(item.type == 'R'){
                _this.isGDflag = true
              }
            })
            res.some(item =>{
              if(item.type == 'D'){
                _this.isYJflag = true
              }
            })
            if (JSON.parse(window.sessionStorage.getItem('EDIT_CONTRACT_SECOND_STEP'))) {
              _this.costItem = JSON.parse(window.sessionStorage.getItem('EDIT_CONTRACT_SECOND_STEP')).costItem;
              return
            }
            for (var i = 0; i < res.length; i++) {
              _this.costItem.push({unitsVal: res[i].unitsVal, unitsCode: res[i].unitsCode, expense_name: res[i].name, amount: '', price: '', priceDay: '', priceMonth: '', priceDayCopy: '', priceMonthCopy: '', expense_period: '', expense_type: res[i].type, late_fee: res[i].lateFee+'%', customPeriod: []})
            }
            // let data = JSON.parse(JSON.stringify(_this.costItem))
            _this.costItem = hlArrayUtil.removeRepeat(_this.costItem, 'expense_name');
          }
        })
      },
      // 验证输入框内为数字
      validateNumber:function(val,e){
        $('#pay-plan, .ct-ceat-btn').hide()
        var result = hlNumberUtil.isPositiveNumber(val)
        if(!result){
          hl.toast('请输入大于或等于0的数字')
          $(e.target).focus().val("")
          return false;
        }
        return true;
      },
      //验证时间
      blurTime: function (n) {
        var d = new Date();
        var day = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
        $('.dt-dateControl').on('click','.day-item',function(){
          setTimeout(function() {
            if (hlDateUtil.shellDate(endDate.value) < hlDateUtil.shellDate(beginDate.value)) {
              hl.toast('结束时间不能小于起始时间')
              endDate.setAttribute('value', '')
            }
          }, 200);
          $('.dt-dateControl').unbind()
        })
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      //验证阶梯时间是否大于上一个
      vaoldDate: function (e) {
        var name = null, _this = this;
        if ($(e.target).hasClass('zdate')) {
          name = e.target;
          $('#pay-plan, .ct-ceat-btn').hide()
        }
        if (!name) return;
        $('.dt-dateControl').on('click','.day-item',function(){
          setTimeout(function() {
            if (hlDateUtil.shellDate($(name).attr('value')) < hlDateUtil.shellDate(beginDate.value)) {
              $(name).attr('value', '')
              hl.toast('选择时间不能小于起始时间')
              return
            }
            if (_this.rentLadder.length > 1) {
              for (var i = 0; i < _this.rentLadder.length; i++) {
                if (hlDateUtil.shellDate($('.zdate').eq(i).attr('value')) >= hlDateUtil.shellDate($('.zdate').eq(i+1).attr('value'))) {
                  _this.rentLadder.splice(i, 1)
									_this.copyRentLadderArr.splice(i, 1)
                  break;
                }
              }
            }
          }, 200);
          $('.dt-dateControl').unbind()
        })
      },
      //验证阶梯时间
      yzJt: function (e, n) {
        var index = null;
        var name = null;
        if ($(e.target).hasClass('zdate')) {
          name = e.target;
          $('#pay-plan, .ct-ceat-btn').hide()
        }
        if ($(e.target).hasClass('bkdate')) {
          name = e.target;
          $('#pay-plan, .ct-ceat-btn').hide()
        }
        if ($(e.target).hasClass('ekdate')) {
          name = e.target;
          $('#pay-plan, .ct-ceat-btn').hide()
        }
        if (!name) return;
        var d = new Date();
        var day = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
        if (!beginDate.value) return;
        if (!endDate.value) return;

        setTimeout(function() {
          if (n == 1) {
            if (hlDateUtil.shellDate($(name).attr('value')) < hlDateUtil.shellDate(beginDate.value)) {
              $(name).attr('value', '')
              hl.toast('选择时间不能小于起始时间')
            }
          }
          if (n == 2) {
            if (hlDateUtil.shellDate($(name).attr('value')) > hlDateUtil.shellDate(endDate.value)) {
              $(name).attr('value', '')
              hl.toast('选择时间不能大于结束时间')
            }
          }
        }, 200);
      },
      //验证租金押金
      validateRentAndDeposit:function(){
        if(!this.rentBill.day){
          hl.toast('提前收款天数不能为空');
          return false;
        }
        if(!this.rentBill.oPrice && this.rentBill.oPrice !== 0){
          hl.toast('租金单价不能为空');
          return false;
        }
        if(!this.rentBill.dRent && this.rentBill.dRent !== 0){
          hl.toast('日租金不能为空');
          return false;
        }
        if(!this.rentBill.mRent && this.rentBill.mRent !== 0){
          hl.toast('月租金不能为空');
          return false;
        }
        if(!this.rentBill.bet && this.rentBill.bet !== 0){
          hl.toast('押付月份不能为空');
          return false;
        }
        if(!this.rentBill.pay && this.rentBill.pay !== 0){
          hl.toast('押付月份不能为空');
          return false;
        }
        if(!this.rentBill.menoy && this.rentBill.menoy !== 0){
          hl.toast('押付钱数不能为空');
          return false;
        }

        return true;
      },
      //点击获取新增费项
      getcostY: function (i, e, type) {
        this.cTIndex = i;
        this.cTType = type;
        if(type === 'P'){
          $('.abs-costitem').css({left: e.srcElement.offsetLeft, top: e.srcElement.offsetTop+40,width:'203px'}).show();
        }
        if(type === 'O'){
          $('.abs-costitem').css({left: e.srcElement.offsetLeft, top: e.srcElement.offsetTop+40,width:'286px'}).show();
        }

        this.getCtData()
        event.stopPropagation()
      },
      getCtData: function () {
        var _this = this;
        hlhttp.get({
          url: 'valid_expenditures',
          success: function (res) {
            _this.cTData = res
          }
        })
      },
      setCost: function (i) {
        // 费项重名验证
        var self = this;
        var flag = true;
        this.costItem.map(function(_item){
          if(_item.expense_name === self.cTData[i].name && self.cTIndex !== i && flag){
            hl.toast('该费项已添加，请重新选择')
            flag = false;
            return false
          }
        })

        if(flag){
          self.costItem[self.cTIndex].expense_name = self.cTData[i].name;
					this.costItem[this.cTIndex].unitsCode = this.cTData[i].unitsCode;
					this.costItem[this.cTIndex].unitsVal = this.cTData[i].unitsVal;
          if(this.cTData[i].lateFee){
            this.costItem[this.cTIndex].late_fee = this.cTData[i].lateFee+'%';
          }else{
            this.costItem[this.cTIndex].late_fee = '0%';
          }
          $('.abs-costitem').hide();
        }

      },
      //删除周期性费项
      delCostItem: function (i) {
        this.costItem.splice(i, 1)
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      //保存
      saveSubmit: function (n) {

        if (!signedDate.value) {
          hl.toast('请选择签订日期')
          return
        }
        if (!this.rentBill.day) {
          hl.toast('请填写提前收款天数')
          return
        }
        if (!beginDate.value || !endDate.value) {
          hl.toast('请选择租赁期限')
          return
        }

        var data = {}, _this = this;
        data.id = this.contractId;
        data.m_code = this.getCtPrevData.zlfData.m_code ? this.getCtPrevData.zlfData.m_code : '#'
        data.c_code = this.getCtPrevData.zlfData.c_code ? this.getCtPrevData.zlfData.c_code : '#'
        data.name = this.getCtPrevData.zlfData.name || '#';
        data.memo = this.getCtPrevData.zlfData.memo ? this.getCtPrevData.zlfData.memo : '#'
        data.contract_type = this.getCtPrevData.contactType.active;
        data.operator_id = JSON.parse(window.localStorage.getItem('userMes')).id.toString();
        data.operator_name = JSON.parse(window.localStorage.getItem('userMes')).name.toString();

        if (this.getCtPrevData.intent.id) {
          data.intent_id = this.getCtPrevData.intent.id
        }

        // 租赁方信息
        var zlfinfo = {
          zlf_type: this.getCtPrevData.zlfType.active,
          zlf_id: this.getCtPrevData.zlfData.zlf_id || '#',
          zlf_name: this.getCtPrevData.zlfData.zlf_name || '#',
          zlf_lperson: this.getCtPrevData.zlfData.zlf_lperson || '#',
          zlf_sperson: this.getCtPrevData.zlfData.zlf_sperson || '#',
          zlf_lphone: this.getCtPrevData.zlfData.zlf_lphone || '#',
          zlf_sphone: this.getCtPrevData.zlfData.zlf_sphone || '#',
          zlf_industry_type: this.getCtPrevData.industryTypes.selected.code,
          zlf_address: this.getCtPrevData.zlfData.zlf_address,
					short_name: this.getCtPrevData.zlfData.shortName,
          idcode:this.getCtPrevData.zlfData.idcode,
          email:this.getCtPrevData.zlfData.email || '#',
          channel_category_code: this.getCtPrevData.channelType.selected.code || '#',
          channel_name_code: this.getCtPrevData.channelName.selected.code || '#',
          channel_name_value: this.getCtPrevData.channelName.selected.name || '#'
        }
        data.zlf_info = JSON.stringify(zlfinfo);
        data.project_info = {};
        data.project_info.project_id = this.getCtPrevData.projectInfo.project_id.toString();
        data.project_info.project_name = this.getCtPrevData.projectInfo.project_name;

        // 单元列表
        if (this.getCtPrevData.projectInfo.units.length > 0) {
          var unitsArr = []
          for (var u = 0; u < this.getCtPrevData.projectInfo.units.length; u++) {
            var unitR = this.getCtPrevData.projectInfo.units[u];
            unitsArr.push({
              "building_id": unitR.building_id,
              "building_name": unitR.building_name,
              "floor_id": unitR.floor_id,
              "floor_num": unitR.floor_num.toString(),
              "unit_id": unitR.unit_id,
              "unit_name": unitR.unit_name,
              "unit_acreage": unitR.unit_acreage.toString()
            })
          }
          data.project_info.units = JSON.stringify(unitsArr);
        } else {
          data.project_info.units = '#';
        }

        // 工位列表
        if (this.wpNum > 0) {
          var wps = this.getCtPrevData.projectInfo.wpdata;
          var wpsArr = []
          for (var w = 0; w < wps.length; w++) {
            for (var p = 0; p < wps[w].stop.length; p++) {
              wpsArr.push({
                building_id: wps[w].building_id,
                building_name: wps[w].building_name,
                floor_id: wps[w].floor_id,
                floor_num: wps[w].floor_num.toString(),
                wp_acreage: '0',
                unit_id: wps[w].unit_id,
                unit_name: wps[w].unit_name,
                "wp_id": wps[w].stop[p].positionId,
                "wp_name": wps[w].stop[p].positionName
              })
            }
          }
          data.project_info.wps = JSON.stringify(wpsArr);
        } else {
          data.project_info.wps = '#'
        }

        // 车位列表
        if (this.stNum > 0) {
          var sts = this.getCtPrevData.projectInfo.stdata;
          var stsArr = []
          for (var s = 0; s < sts.length; s++) {
            for (var t = 0; t < sts[s].stop.length; t++) {
              stsArr.push({
                building_id: sts[s].building_id,
                building_name: sts[s].building_name,
                floor_id: sts[s].floor_id,
                floor_num: sts[s].floor_num.toString(),
                stop_acreage: '0',
                unit_id: sts[s].unit_id,
                unit_name: sts[s].unit_name,
                "stop_id": sts[s].stop[t].positionId,
                "stop_name": sts[s].stop[t].positionName
              })
            }
          }
          data.project_info.stops = JSON.stringify(stsArr);
        } else {
          data.project_info.stops = '#'
        }
        // 项目信息
        data.project_info = JSON.stringify(data.project_info);

        // 租金信息
        var zdate = document.querySelectorAll('.zdate');
        var zdateArr = []; // 阶梯递增开始日期
        var zPriceArr = []; // 阶梯递增租金单价
        var rzjArr = []; //日租金
        var yzjArr = []; //月租金
        var lvArr = []; //租金递增率

        for (var z = 0; z < this.rentLadder.length; z++) {
          zdateArr.push(zdate[z].getAttribute('value'))
          zPriceArr.push(this.copyRentLadderArr[z].dj)
          rzjArr.push(this.copyRentLadderArr[z].rz)
          yzjArr.push(this.copyRentLadderArr[z].yz)
          lvArr.push(Number(this.copyRentLadderArr[z].lv.replace('%', ''))/100)
        }
        zdateArr.unshift(beginDate.value)
        zPriceArr.unshift(this.rentBill.oPrice)
        rzjArr.unshift(this.rentBill.dRent)
        yzjArr.unshift(this.rentBill.mRent)
        lvArr.unshift('0')

        data.rent_info = {
          'rent_way':this.setRent.active.toString(),
          'rent_price':this.rentBill.oPrice.toString() || '0',
          'rent_price_day':this.rentBill.dRent.toString() || '0',
          'rent_price_month':this.rentBill.mRent.toString() || '0',
          'rent_increse_date':zdateArr.join(','),
          'rent_increse_price':zPriceArr.join(','),
          'rent_increse_day':rzjArr.join(','),
          'rent_increse_month':yzjArr.join(','),
          'rent_increse_percent':lvArr.join(','),
          'rent_late_fee':this.rentBill.proportion.toString() || '0',
          'bill_date_fix_num': this.rentBill.day+'' || '1',
          'sign_time':$('#signedDate').attr('value'),
          'deposit':this.rentBill.menoy ? this.rentBill.menoy.toString() : '0',
          'deposit_period':this.rentBill.bet ? this.rentBill.bet.toString() : '0',
          'payment_period':this.rentBill.pay ? this.rentBill.pay.toString() : '0',
          'begin_date':beginDate.value.toString(),
          'end_date':endDate.value.toString(),
          bill_date_BOA: this.billDate.act,
          bill_date_fix_type: this.billDate.act1,
          first_payment_date: SqDate.value,
					rent_increase_way: this.ladderRentActive
        };
        var bkdate = document.querySelectorAll('.bkdate');
        var ekdate = document.querySelectorAll('.ekdate');
        var mdate = [];
        for (var i = 0; i < bkdate.length; i++) {
          mdate.push(bkdate[i].getAttribute('value')+'~'+ekdate[i].getAttribute('value'))
        }
        if(mdate.length !== 0){
          data.rent_info.free_date = mdate.join(',')
        }else{
          data.rent_info.free_date = '#'
        }


        data.rent_info.rent_price_unit = this.setRent.active
        data.rent_info.rent_way = this.setRent.active
        data.rent_info = JSON.stringify(data.rent_info);

        this.costItem.map(item =>{
          if(item.expense_type == 'T'){
            item.expense_flow_type = item.amount > 0?'RC':'RF'
          }else{
            item.expense_flow_type = 'RC'
          }
        })
        // 费用信息
        var costItemArr = JSON.parse(JSON.stringify(this.costItem));

        for (var i = 0; i < costItemArr.length; i++) {
					costItemArr[i].priceDay = JSON.parse(JSON.stringify(costItemArr[i].priceDayCopy))
					costItemArr[i].priceMonth = JSON.parse(JSON.stringify(costItemArr[i].priceMonthCopy))
					costItemArr[i].units_code = costItemArr[i].unitsCode ? costItemArr[i].unitsCode : '#'
          if (costItemArr[i].amount == '') {
            costItemArr[i].amount = '0'
          }
          if (costItemArr[i].price == '') {
            costItemArr[i].price = '0'
          }
          if (costItemArr[i].priceDay == '') {
            costItemArr[i].priceDay = '0'
          }
          if (costItemArr[i].priceMonth == '') {
            costItemArr[i].priceMonth = '0'
          }
          if (costItemArr[i].expense_period == '') {
            costItemArr[i].expense_period = '0'
          }
          if (costItemArr[i].late_fee == '') {
            costItemArr[i].late_fee_percent = '0'
          } else {
            costItemArr[i].late_fee_percent = (Number(costItemArr[i].late_fee.replace('%', ''))/100).toString()
          }
          if (!costItemArr[i].customPeriod.length) {
            costItemArr[i].custom_period = '#'
          }
          if (costItemArr[i].customPeriod.length) {
            costItemArr[i].custom_period = costItemArr[i].customPeriod
          }
          delete costItemArr[i].customPeriod;
        }

        // 将固定租金和租金押金加入费项中
        if (this.isYJflag && this.rentDepositFlag) {
          costItemArr.push({
            'amount':'0',
            'custom_period':'#',
            "expense_name": '固定租金',
            'expense_flow_type':'RC',
            "late_fee_percent": this.rentBill.rentPercent?this.rentBill.rentPercent/100 + '' : '0', //租金滞纳金比列
            'expense_period':'0',
            'expense_type':'R',
            'late_fee':'0',
            'priceDayCopy':'',
            'price':this.oPrice,
            "priceDay": this.dRent,
            "priceMonth": this.mRent,
            'priceMonthCopy':'',
            'units_code':'#'
          })
        }
        if (this.isGDflag && this.rentFlag) {
          costItemArr.push({
            "amount": this.menoy ? Number(this.menoy).toFixed(2)+'' : '0',
            'custom_period':'#',
            "expense_name": '押金',
            'expense_flow_type':'RC',
            "late_fee_percent": this.rentBill.proportion?this.rentBill.proportion/100 + '': '0', //押金滞纳金比列
            'expense_period':'0',
            'expense_type':'D',
            'late_fee':'0',
            'price':'0',
            'priceDay':'0',
            'priceDayCopy':'',
            'priceMonth':'0',
            'priceMonthCopy':'',
            'units_code':'#'
          })
				}

        	//营业额全部传0，类型 CM
				if (this.yyeFlag) {
					costItemArr.push({
            "amount": '0',
            "custom_period": '#',
            "expense_name": '营业额抽成',
            'expense_flow_type':'RC',
            "late_fee_percent": '0',
					  "expense_period": this.tableArr[0].payemnt_period ? this.tableArr[0].payemnt_period + '' : '#',
            "expense_type": 'CM',
					  "price": '0',
					  "priceDay": '0',
					  "priceMonth": '0',
            "units_code": "#",
            "payment_date_config": this.paymentTypeCode || '#',
            "commission_date_boa": this.billDateQHcode || '#',
            "commission_date_fix_type": this.billDaycode || '#',
            "commission_date_fix_num": this.paymentTypeCode == 'BL'? this.rentBill.day + '':this.dayNum + ''
					})
				}
        data.expense = JSON.stringify(costItemArr);
        data.bill_plans = JSON.stringify(payPlan.exportPayPlanData());

				if (this.yyeFlag) {

					data.commission_info = {};
					let rules = [];
					this.tableArr.map(item => {
						rules.push({
							"base_val_down_limit": item.base_val_down_limit.toString(),
							 "base_val_up_limit": item.base_val_up_limit.toString(),
							 "commission_percent": item.commission_percent.toString(),
							 "commission_down_limit": item.commission_down_limit ? item.commission_down_limit.toString() : '#',
							 "commission_up_limit": item.commission_up_limit ? item.commission_up_limit.toString() : '#',
							 "late_fee_percent": item.late_fee_percent ? item.late_fee_percent.toString() : '#'
						})
					})
					rules[rules.length-1].base_val_up_limit = '不限'
					let commission_info_data = {
						commission_type: this.turnoverCode,
						compare_rent_amt_flag: this.turnoverCheckBox,
						payment_period: this.tableArr[0].payemnt_period + '' || '#',
            payment_date_config: this.paymentTypeCode,
            commission_date_boa: this.paymentTypeCode == 'BL'? this.billDate.act:this.billDateQHcode,
            commission_date_fix_type: this.paymentTypeCode == 'BL'? this.billDate.act1:this.billDaycode,
            commission_date_fix_num: this.paymentTypeCode == 'BL'? this.rentBill.day + '':this.dayNum + '',
            rules: JSON.stringify(rules)
					}
					data.commission_info = JSON.stringify(commission_info_data) || '#'
				}

        console.log(data)
        if (n == 1) {
          hlhttp.post({
            url: 'contract/_submit',
            data: data,
            success: (res) => {
              hl.toast('生成合同成功');
              var keyArr = [
                'EDIT_CONTRACT_FIRST_STEP',
                'EDIT_CONTRACT_SECOND_STEP'
              ]
              hlStorage.ssClearMultipleKey(keyArr)
              hlUrlUtil.goTo('contractNewDeatil', {id: this.contractId, proId: this.getCtPrevData.projectInfo.project_id.toString(), ddtab:true})
            }
          })
        }
        if (n == 2) {
          hlhttp.put({
            url: 'contract',
            data: data,
            success: (res) => {
              hl.toast('保存合同成功');
              var keyArr = [
                'EDIT_CONTRACT_FIRST_STEP',
                'EDIT_CONTRACT_SECOND_STEP'
              ]
              hlStorage.ssClearMultipleKey(keyArr)
              hlUrlUtil.goTo('contractNewDeatil', {id: this.contractId, proId: this.getCtPrevData.projectInfo.project_id.toString(), ddtab:true})
            }
          })
        }
      },
      fkjh1: function () {
        // 验证
        var self = this;
        var flag = self.validateRentAndDeposit()
        if(!flag){ return false }
        if (!endDate.value) {
          return
        }

        var data = {};
        var zdate = document.querySelectorAll('.zdate');
        var zdateArr = [];
        var rzjArr = []; //日租金
        var yzjArr = []; //月租金
        var lvArr = []; //租金递增率
        for (var z = 0; z < this.rentLadder.length; z++) {
          zdateArr.push(zdate[z].getAttribute('value'))
          rzjArr.push(this.copyRentLadderArr[z].rz)
          yzjArr.push(this.copyRentLadderArr[z].yz)
          lvArr.push(this.copyRentLadderArr[z].lv.replace('%', ''))
        }
        zdateArr.unshift(beginDate.value)
        rzjArr.unshift(this.rentBill.dRent)
        yzjArr.unshift(this.rentBill.mRent)
        lvArr.unshift('0')
        var bkdate = document.querySelectorAll('.bkdate');
        var ekdate = document.querySelectorAll('.ekdate');
        var mdate = [];

        for (var i = 0; i < bkdate.length; i++) {
          mdate.push(bkdate[i].getAttribute('value')+'~'+ekdate[i].getAttribute('value'))
        }

        data.contract = {
          rent_way: this.setRent.active,
          period: this.rentBill.pay.toString() || '0',
          free_date: mdate.join(',') || '#',
          // tpayment_days: this.rentBill.day.toString(),
          rent_late_fee_percent: Number(this.rentBill.proportion/100).toString(),
          rent_increse_days: rzjArr.join(','),
          rent_increse_months: yzjArr.join(','),
          rent_increse_dates: zdateArr.join(','),
          begin_date: beginDate.value,
          end_date: endDate.value,
          bill_date_BOA: this.billDate.act,
          bill_date_fix_type: this.billDate.act1,
          first_payment_date: SqDate.value,
          bill_date_fix_num: this.rentBill.day+'',
					rent_increase_way: this.ladderRentActive
        }

        data.expenses = [];

        for (var i = 0; i < this.costItem.length; i++) {
          // 验证费项
          if(this.costItem[i].expense_type == 'P'){
            if(!this.costItem[i].expense_name && this.costItem[i].expense_name !== 0){
              hl.toast('请填写周期性费项名称')
              return false;
            }
            if(!this.costItem[i].priceDay && this.costItem[i].priceDay !== 0){
              hl.toast('请填写周期性费项日金额')
              return false;
            }
            if(!this.costItem[i].priceMonth && this.costItem[i].priceMonth !== 0){
              hl.toast('请填写周期性费项月金额')
              return false;
            }
            if(!this.costItem[i].expense_period && this.costItem[i].expense_period !== 0){
              hl.toast('请填写周期性费项付款周期')
              return false;
            }
            if(!this.costItem[i].late_fee && this.costItem[i].late_fee !== 0){
              hl.toast('请填写周期性费项滞纳金比例')
              return false;
            }
          }
          if(this.costItem[i].expense_type == 'O'){
            if(!this.costItem[i].expense_name && this.costItem[i].expense_name !== 0){
              hl.toast('请填写一次性费项名称')
              return false;
            }
            if(!this.costItem[i].amount && this.costItem[i].amount !== 0){
              hl.toast('请填写一次性费项总金额')
              return false;
            }
            if(!this.costItem[i].late_fee && this.costItem[i].late_fee !== 0){
              hl.toast('请填写一次性费项滞纳金比例')
              return false;
            }
          }
          if(this.costItem[i].expense_type == 'T'){
            if(!this.costItem[i].expense_name && this.costItem[i].expense_name !== 0){
              hl.toast('请填写临时费项名称')
              return false;
            }
            if(!this.costItem[i].amount && this.costItem[i].amount !== 0){
              hl.toast('请填写临时费项总金额')
              return false;
            }
          }
          if (!this.costItem[i].customPeriod) {
            this.costItem[i].customPeriod = []
          }

          var aCrr = []
          aCrr = JSON.parse(JSON.stringify(this.costItem[i].customPeriod));
          if(!this.costItem[i].customPeriod.length) {
            aCrr = '#'
          }

          data.expenses.push({
            "name": this.costItem[i].expense_name,
            "period": this.costItem[i].expense_period || '0',
            "amount": this.costItem[i].amount || '0',
            "price": this.costItem[i].price || '0',
            "priceDay": this.costItem[i].priceDayCopy || '0',
            "priceMonth": this.costItem[i].priceMonthCopy || '0',
            "late_fee_percent": (Number(this.costItem[i].late_fee.replace('%', ''))/100).toString() || '0',
            "expense_type": this.costItem[i].expense_type,
            custom_period: aCrr || '#'
          })
        }

				if (this.yyeFlag) {
					let flag0 = false, flag1 = false, flag2 = false;
					let newArr = JSON.parse(JSON.stringify(this.tableArr))
					newArr[newArr.length-1].base_val_up_limit = '不限'
					newArr.map(item => {
						if (!item.base_val_up_limit) {
							flag0 = true;
						}
						if (!item.commission_percent) {
							flag1 = true;
						}
						if (!item.payemnt_period) {
							flag2 = true;
						}
					})
					if (flag0) {
						hl.toast('请填写营业额抽成基数上限')
						return
					}
					if (flag1) {
						hl.toast('请填写营业额抽成比例')
						return
					}
					if (flag2) {
						hl.toast('请填写营业额抽成付款周期')
						return
					}
				}

        if (this.isYJflag && this.rentDepositFlag) {
					data.expenses.unshift({
					  "name": '押金',
					  "period": '0',
					  "amount": this.menoy ? Number(this.menoy).toFixed(2)+'' : '0',
					  "price": '0',
					  "priceDay": '0',
					  "priceMonth": '0',
					  "late_fee_percent": this.rentBill.proportion? this.rentBill.proportion/100 + '' : '0', //押金滞纳金比列
					  "expense_type": 'D',
					  "custom_period": '#',
						"units_code": "#"
					})
        }
        if (this.isGDflag && this.rentFlag) {
					data.expenses.unshift({
					  "name": '固定租金',
					  "period": '0',
					  "amount": '0',
					  "price": this.oPrice,
					  "priceDay": this.dRent,
					  "priceMonth": this.mRent,
					  "late_fee_percent": this.rentBill.rentPercent? this.rentBill.rentPercent/100 + '' : '0', //押金滞纳金比列
					  "expense_type": 'R',
					  "custom_period": '#',
						"units_code": "#",
					})
				}

				//营业额全部传0，类型 CM
				if (this.yyeFlag) {
					data.expenses.push({
					  "name": '营业额抽成',
					  "period": this.tableArr[0].payemnt_period ? this.tableArr[0].payemnt_period + '' : '#',
					  "amount": '0',
					  "price": '0',
					  "priceDay": '0',
					  "priceMonth": '0',
					  "late_fee_percent": '0',
					  "expense_type": 'CM',
					  "custom_period": '#',
            "units_code": "#",
            "payment_date_config": this.paymentTypeCode || '#',
            "commission_date_boa": this.billDateQHcode || '#',
            "commission_date_fix_type": this.billDaycode || '#',
            "commission_date_fix_num": this.paymentTypeCode == 'BL'? this.rentBill.day + '':this.dayNum + ''
					})
				}
        hlhttp.get({
          url: 'contracts/bill_plans',
          data: {contract_id: this.contractId},
          success: function (res) {
            payPlan.init()
            payPlan.emptyPayPlanData()
            payPlan.payDataDeal(res)
            payPlan.editPayPlan()
            payPlan.editBillEndDate(endDate.value, data)
          }
        })

      },
      //生成计划
      fkjh: function () {
        // 验证
        var self = this;
        var flag = self.validateRentAndDeposit()
        if(!flag){ return false }
        if (!endDate.value) {
          return
        }
        if (this.yyeFlag) {
					let flag0 = false, flag1 = false, flag2 = false;
					let newArr = JSON.parse(JSON.stringify(this.tableArr))
					newArr[newArr.length-1].base_val_up_limit = '不限'
					newArr.map(item => {
						if (!item.base_val_up_limit) {
							flag0 = true;
						}
						if (!item.commission_percent) {
							flag1 = true;
						}
						if (!item.payemnt_period) {
							flag2 = true;
						}
					})
					if (flag0) {
						hl.toast('请填写营业额抽成基数上限')
						return
					}
					if (flag1) {
						hl.toast('请填写营业额抽成比例')
						return
					}
					if (flag2) {
						hl.toast('请填写营业额抽成付款周期')
						return
					}
				}
        var data = {};
        var zdate = document.querySelectorAll('.zdate');
        var zdateArr = [];
        var rzjArr = []; //日租金
        var yzjArr = []; //月租金
        var lvArr = []; //租金递增率
        for (var z = 0; z < this.rentLadder.length; z++) {
          zdateArr.push(zdate[z].getAttribute('value'))
          rzjArr.push(this.copyRentLadderArr[z].rz)
          yzjArr.push(this.copyRentLadderArr[z].yz)
          lvArr.push(this.copyRentLadderArr[z].lv.replace('%', ''))
        }
        zdateArr.unshift(beginDate.value)
        rzjArr.unshift(this.rentBill.dRent)
        yzjArr.unshift(this.rentBill.mRent)
        lvArr.unshift('0')
        var bkdate = document.querySelectorAll('.bkdate');
        var ekdate = document.querySelectorAll('.ekdate');
        var mdate = [];

        for (var i = 0; i < bkdate.length; i++) {
          mdate.push(bkdate[i].getAttribute('value')+'~'+ekdate[i].getAttribute('value'))
        }

        data.contract = {
          rent_way: this.setRent.active,
          period: this.rentBill.pay.toString() || '0',
          free_date: mdate.join(',') || '#',
          rent_late_fee_percent: Number(this.rentBill.proportion/100).toString(),
          rent_increse_days: rzjArr.join(','),
          rent_increse_months: yzjArr.join(','),
          rent_increse_dates: zdateArr.join(','),
          begin_date: beginDate.value,
          end_date: endDate.value,
          bill_date_BOA: this.billDate.act,
          bill_date_fix_type: this.billDate.act1,
          first_payment_date: SqDate.value,
          bill_date_fix_num: this.rentBill.day+'',
					rent_increase_way: this.ladderRentActive
        }

        data.expenses = [];
				for (let j = 0; j < this.costItem.length; j++) {
					if (this.costItem[j].expense_type == 'CM') {
						this.costItem.splice(j, 1)
					}
        }
        for (let j = 0; j < this.costItem.length; j++) {
					if (this.costItem[j].expense_type == 'D') {
						this.costItem.splice(j, 1)
          }
        }

        for (let j = 0; j < this.costItem.length; j++) {
					if (this.costItem[j].expense_type == 'R') {
						this.costItem.splice(j, 1)
          }
				}
        for (var i = 0; i < this.costItem.length; i++) {
          // 验证费项
          if(this.costItem[i].expense_type == 'P'){
            if(!this.costItem[i].expense_name && this.costItem[i].expense_name !== 0){
              hl.toast('请填写周期性费项名称')
              return false;
            }
            if(!this.costItem[i].priceDay && this.costItem[i].priceDay !== 0){
              hl.toast('请填写周期性费项日金额')
              return false;
            }
            if(!this.costItem[i].priceMonth && this.costItem[i].priceMonth !== 0){
              hl.toast('请填写周期性费项月金额')
              return false;
            }
            if(!this.costItem[i].expense_period && this.costItem[i].expense_period !== 0){
              hl.toast('请填写周期性费项付款周期')
              return false;
            }
            if(!this.costItem[i].late_fee && this.costItem[i].late_fee !== 0){
              hl.toast('请填写周期性费项滞纳金比例')
              return false;
            }
          }
          if(this.costItem[i].expense_type == 'O'){
            if(!this.costItem[i].expense_name && this.costItem[i].expense_name !== 0){
              hl.toast('请填写一次性费项名称')
              return false;
            }
            if(!this.costItem[i].amount && this.costItem[i].amount !== 0){
              hl.toast('请填写一次性费项总金额')
              return false;
            }
            if(!this.costItem[i].late_fee && this.costItem[i].late_fee !== 0){
              hl.toast('请填写一次性费项滞纳金比例')
              return false;
            }
          }
          if(this.costItem[i].expense_type == 'T'){
            if(!this.costItem[i].expense_name && this.costItem[i].expense_name !== 0){
              hl.toast('请填写临时费项名称')
              return false;
            }
            if(!this.costItem[i].amount && this.costItem[i].amount !== 0){
              hl.toast('请填写临时费项总金额')
              return false;
            }
          }
          if (!this.costItem[i].customPeriod) {
            this.costItem[i].customPeriod = []
          }

          var aCrr = []
          if (!this.costItem[i].customPeriod) {
            this.costItem[i].customPeriod = []
          }
          aCrr = JSON.parse(JSON.stringify(this.costItem[i].customPeriod));
          if(!this.costItem[i].customPeriod.length) {
            aCrr = '#'
          }

          data.expenses.push({
            "name": this.costItem[i].expense_name,
            "period": this.costItem[i].expense_period || '0',
            "amount": this.costItem[i].amount || '0',
            "price": this.costItem[i].price || '0',
            "priceDay": this.costItem[i].priceDayCopy || '0',
            "priceMonth": this.costItem[i].priceMonthCopy || '0',
            "late_fee_percent": (Number(this.costItem[i].late_fee.replace('%', ''))/100).toString() || '0',
            "expense_type": this.costItem[i].expense_type,
            'custom_period': aCrr || '#',
            "units_code": this.costItem[i].unitsCode ? this.costItem[i].unitsCode : '#',
            // "payment_date_config":  '#',
            // "commission_date_boa":  '#',
            // "commission_date_fix_type":  '#',
            // "commission_date_fix_num":  this.rentBill.day,
          })
        }

        if (this.isYJflag && this.rentDepositFlag){
          data.expenses.unshift({
            "name": '押金',
					  "period": '0',
					  "amount": this.menoy ? Number(this.menoy).toFixed(2)+'' : '0',
					  "price": '0',
					  "priceDay": '0',
					  "priceMonth": '0',
					  "late_fee_percent": this.rentBill.proportion? this.rentBill.proportion/100 + '' : '0', //押金滞纳金比列
					  "expense_type": 'D',
					  "custom_period": '#',
						"units_code": "#"
          })
        }
        if (this.isGDflag && this.rentFlag){
          data.expenses.unshift({
            "name": '固定租金',
					  "period": '0',
					  "amount": '0',
					  "price": this.oPrice,
					  "priceDay": this.dRent,
					  "priceMonth": this.mRent,
					  "late_fee_percent": this.rentBill.rentPercent? this.rentBill.rentPercent/100 + '' : '0', //押金滞纳金比列
					  "expense_type": 'R',
					  "custom_period": '#',
						"units_code": "#",
          })
        }

        payPlan.createPayPlan(data)
        payPlan.editPayPlan()
        payPlan.editBillEndDate(endDate.value, data)
      },
      // 判断价格是否符合底价策略
      isSatisfyMinPrice:function(){
        var self = this;
        var prevData = self.getCtPrevData
        // 所选合同类型  WP 工位   UN 单元
        var type = prevData.contactType.active === 'WR' ? 'WP' : 'UN'
        // 所选单元或者工位id  如果只选车位 则不掉用底价策略
        var getUnitIds = function(){
          var res = [];
          prevData.unitData.map(function(_item){
            res.push(_item.unit_id)
          })
          return res.join()
        }
        var getWpIds = function(){
          var res = [];
          prevData.wpData.map(function(item){
            item.stop.map(function(_item){
              res.push(_item.positionId)
            })
          })
          return res.join()
        }
        var ids = null;
        if(type === 'WP'){ ids = getWpIds()}
        if(type === 'UN'){ ids = getUnitIds()}
        // 日租金、月租金计算
        var acreage = self.wpNum ? self.wpNum : this.utAge;
        var rentPriceDay = self.rentBill.dRent / acreage;
        var rentPriceMonth = self.rentBill.mRent / acreage

        if(prevData.unitData.length !== 0 || prevData.wpData.length !== 0){
          hlhttp.put({
            url:'check_base_price_policy',
            data:{
              rent_price_day:Number(rentPriceDay).toFixed(2),
              rent_price_month:Number(rentPriceMonth).toFixed(2),
              type:type,
              ids:ids
            },
            success:function(data){
              if(data.result === 'N'){
                if(data.rentPriceType === 'D'){
                  if(type === 'WP'){
                    self.dayRentPriceAlert = '(日租金低于工位底价' + data.memo + '元/个/天)'
                    self.monthRentPriceAlert = ''
                  }
                  if(type === 'UN'){
                    self.dayRentPriceAlert = '(日租金低于单元底价' + data.memo + '元/m²/天)'
                    self.monthRentPriceAlert = ''
                  }
                }
                if(data.rentPriceType === 'M'){
                  if(type === 'WP'){
                    self.monthRentPriceAlert = '(月租金低于工位底价' + (Number(data.memo)).toFixed(2) + '元/个/天)'
                    self.dayRentPriceAlert = ''
                  }
                  if(type === 'UN'){
                    self.monthRentPriceAlert ='(月租金低于单元底价' + (Number(data.memo)).toFixed(2) + '元/m²/天)'
                    self.dayRentPriceAlert = ''
                  }
                }
                if(data.rentPriceType === 'A'){
                  if(type === 'WP'){
                    self.dayRentPriceAlert = '(日租金低于工位底价' + data.memo.split(',')[0] + '元/个/天)'
                    self.monthRentPriceAlert ='(月租金低于工位底价' + Number(data.memo.split(',')[1] || '0').toFixed(2) + '元/个/月)'
                  }
                  if(type === 'UN'){
                    self.dayRentPriceAlert = '(日租金低于单元底价' + data.memo.split(',')[0] + '元/m²/天)'
                    self.monthRentPriceAlert ='(月租金低于单元底价' + Number(data.memo.split(',')[1] || '0').toFixed(2) + '元/m²/月)'
                  }
                }
              }
              if(data.result === 'Y'){
                self.dayRentPriceAlert = ''
                self.monthRentPriceAlert = ''
              }
            }
          })
        }
      }
    },
    beforeMount: function () {
      var self = this;
      if (window.sessionStorage.getItem('EDIT_CONTRACT_SECOND_STEP')) {
        var prevData = JSON.parse(window.sessionStorage.getItem('EDIT_CONTRACT_FIRST_STEP'));     // 上一步的信息
        var data = JSON.parse(window.sessionStorage.getItem('EDIT_CONTRACT_SECOND_STEP'));    // 下一步的信息
        // 如果第一步时编辑更改了合同类型 或者 面积、工位数 ，则租金押金信息及阶梯租金信息全重置为空
        // console.log(prevData.contactType.active + ':' + data.getCtPrevData.contactType.active)
        // console.log(self.utAge + ':' + data.unitTotalAcreage)
        // console.log(self.wpNum + ':' + data.getCtPrevData.wpNum)
        if(prevData.contactType.active === data.getCtPrevData.contactType.active && Number(self.utAge).toFixed(2) == Number(data.unitTotalAcreage).toFixed(2) && self.wpNum == data.getCtPrevData.wpNum){
          this.rentBill = data.rentBill;
          this.rentLadder = data.rentLadder;
          this.copyRentLadderArr = data.copyRentLadderArr;
          // this.oPrice = data.rentBill.oPrice;
          // this.dRent = data.rentBill.dRent;
          // this.mRent = data.rentBill.mRent
        }
        this.contractId = data.contractId;
        this.rentBill.day = data.rentBill.day;
        this.billDate = data.billDate;
        this.setYear = data.setYear;
        this.setRent = data.setRent;
        this.setUnit = data.setUnit;
        this.freePeriod = data.freePeriod;
        // this.costItem = data.costItem;
        this.oPrice = data.oPrice;
        this.dRent = data.dRent;
        this.mRent = data.mRent;
				this.ladderRentArr = data.ladderRentArr
				this.ladderRentActive = data.ladderRentActive

      }else{
        this.getContractDetail()
      }
    },
    mounted: function () {
      var self = this;
      hlSelectUi(true)
      this.yzDate()
			this.CHOUCHENGDt()
      this.ladderRentConfig()
      this.getSelfRent()
      // this.getCostItem()
      $(document.body).click(function(event) {
        if (!$(event.target).hasClass('maopao')) {
          $('.abs-costitem').hide();
        }
      });
      // this.yzunitwp()
      //点击下一步拿本地数据
      if (window.sessionStorage.getItem('EDIT_CONTRACT_SECOND_STEP')) {
        signedDate.setAttribute('value', JSON.parse(window.sessionStorage.getItem('EDIT_CONTRACT_SECOND_STEP')).sDate);
        beginDate.setAttribute('value', JSON.parse(window.sessionStorage.getItem('EDIT_CONTRACT_SECOND_STEP')).bDate);
        endDate.setAttribute('value', JSON.parse(window.sessionStorage.getItem('EDIT_CONTRACT_SECOND_STEP')).eDate);
        SqDate.setAttribute('value', JSON.parse(window.sessionStorage.getItem('EDIT_CONTRACT_SECOND_STEP')).billDate.sqDate);
        var zdate = document.querySelectorAll('.zdate');
        for (var i = 0; i < this.rentLadder.length; i++) {
          zdate[i].setAttribute('value', this.rentLadder[i].time)
        }
        var bkdate = document.querySelectorAll('.bkdate');
        var ekdate = document.querySelectorAll('.ekdate');
        for (var i = 0; i < this.freePeriod.length; i++) {
          bkdate[i].setAttribute('value', this.freePeriod[i].btime)
          ekdate[i].setAttribute('value', this.freePeriod[i].etime)
        }
      }else{
        setTimeout(function(){
          self.showContractDetail(self.contractDetail)
        },2000)
      }
    }
  })
} ())
